rethinkdb-mock v0.0.1
rethinkdb-mock v0.7.1
Spec-compliant unit-testing for RethinkDB queries
The end goal is to replicate the API of rethinkdbdash
.
For all intents and purposes, you should get the same results.
Please review the Feature support table before opening an issue.
Reusing and nesting queries are fully supported. :+1:
Check out the Releases tab for details about the newest versions.
Why use this?
- Load JSON data into the database with
db.load()
- Or call
db.init()
to easily populate the database - Easily run specific tests (
fit
in Jasmine) - Avoid teardown between test suites
- Avoid having to start a
rethinkdb
process before you can run tests - Avoid mutilating your development
rethinkdb_data
- Continuous integration compatibility
Getting started
- Install from Github:
npm install --save-dev rethinkdb-mock
- Put some boilerplate in your test environment:
const rethinkdb = require('rethinkdb-mock')
// Replace `rethinkdbdash` with `rethinkdb-mock`
const mock = require('mock-require')
mock('rethinkdbdash', rethinkdb)
// You must use the same database name as the code you're testing.
const db = rethinkdb({
name: 'test' // The default value
})
- Use it in your test suites:
describe('Some test suite', () => {
// Reset the database between suites.
beforeAll(() => {
db.init({
users: [],
friends: [],
})
// Optionally, load JSON into the database.
db.load(__dirname, './data.json')
})
// Now create your tests...
})
Feature support
The entire Rethink API is not yet implemented. Get an idea of what's supported by referencing the table below.
Open an issue to request a feature be implemented. But try implementing it yourself if you have time! :+1:
If a method is not behaving as expected, please open an issue!
But first check out TODO.md
for a list of missing behaviors.
â means "not implemented yet"
â ď¸ means "partially implemented"
đŻ means "fully implemented"
% | Feature |
---|---|
â | Changefeeds |
â | Binary support |
â | Date-time support |
â | Geospatial support |
đŻ | r.table() |
đŻ | r.tableCreate() |
â | r.tableList() |
đŻ | r.tableDrop() |
â | r.indexCreate() |
â | r.indexList() |
â | r.indexDrop() |
â | r.indexRename() |
â | r.indexStatus() |
â | r.indexWait() |
â ď¸ | r.row |
đŻ | r() or r.expr() |
đŻ | r.do() |
â | r.args() |
đŻ | r.object() |
đŻ | r.branch() |
â ď¸ | r.typeOf() |
đŻ | r.uuid() |
â ď¸ | r.desc() |
â ď¸ | r.asc() |
â | r.js() |
â | r.json() |
â | r.http() |
â | r.error() |
â | r.range() |
đŻ | table.get() |
đŻ | table.getAll() |
â ď¸ | table.insert() |
đŻ | table.delete() |
đŻ | query() or query.bracket() |
đŻ | query.nth() |
đŻ | query.getField() |
â ď¸ | query.hasFields() |
â | query.withFields() |
â ď¸ | query.offsetsOf() |
â ď¸ | query.contains() |
â ď¸ | query.orderBy() |
đŻ | query.isEmpty() |
đŻ | query.count() |
đŻ | query.skip() |
đŻ | query.limit() |
đŻ | query.slice() |
â | query.between() |
đŻ | query.merge() |
đŻ | query.pluck() |
â ď¸ | query.without() |
â ď¸ | query.replace() |
â ď¸ | query.update() |
â ď¸ | query.delete() |
đŻ | query.default() |
đŻ | query.and() |
đŻ | query.or() |
â ď¸ | query.eq() |
â ď¸ | query.ne() |
â ď¸ | query.gt() |
â ď¸ | query.lt() |
â ď¸ | query.ge() |
â ď¸ | query.le() |
â ď¸ | query.add() |
â ď¸ | query.sub() |
â ď¸ | query.mul() |
đŻ | query.div() |
â | query.mod() |
â | query.sum() |
â | query.avg() |
â | query.min() |
â | query.max() |
â | query.not() |
â | query.ceil() |
â | query.floor() |
â | query.round() |
â | query.random() |
â | query.coerceTo() |
đŻ | query.map() |
â ď¸ | query.filter() |
â | query.fold() |
â | query.reduce() |
â | query.forEach() |
â | query.distinct() |
â | query.concatMap() |
â | query.innerJoin() |
â | query.outerJoin() |
â | query.eqJoin() |
â | query.zip() |
â | query.group() |
â | query.ungroup() |
â | query.sample() |
â | query.setInsert() |
â | query.setUnion() |
â | query.setIntersection() |
â | query.setDifference() |
â | query.append() |
â | query.prepend() |
â | query.union() |
â | query.difference() |
â | query.insertAt() |
â | query.spliceAt() |
â | query.deleteAt() |
â | query.changeAt() |
â | query.keys() |
â | query.values() |
â | query.literal() |
â | query.match() |
â | query.split() |
â | query.upcase() |
â | query.downcase() |
â | query.toJSON() or query.toJsonString() |
â | query.info() |
â | query.sync() |
Contributing
Issues and pull requests are always appreciated! :grin:
If you have any questions, feel free to open an issue.
Getting started
# This tool compiles the `src` directory during `npm install`.
npm install -g coffee-build
git clone https://github.com/aleclarson/rethinkdb-mock
npm install
# Manually compile the `src` directory after you make any changes.
coffee -cb -o js src
Similar repositories
- JohanObrink/rethink-mock: Stubs for
sinon
(last updated October 2017) - vasc/rethinkdb-mock: Small subset of Rethink API, not spec-compliant (last updated April 2014)