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.
db.load()
db.init()
to easily populate the databasefit
in Jasmine)rethinkdb
process before you can run testsrethinkdb_data
npm install --save-dev rethinkdb-mock
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
})
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...
})
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() |
Issues and pull requests are always appreciated! :grin:
If you have any questions, feel free to open an issue.
# 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
sinon
(last updated October 2017)