Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
✅ add failing tests for maybeError() and closed db
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphtheninja committed Aug 29, 2017
1 parent 98587eb commit 1f8d697
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_levelup_test_db_61
84 changes: 84 additions & 0 deletions test/maybe-error-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* Copyright (c) 2012-2017 LevelUP contributors
* See list at <https://github.com/level/levelup#contributing>
* MIT License <https://github.com/level/levelup/blob/master/LICENSE.md>
*/

var common = require('./common')
var assert = require('referee').assert
var refute = require('referee').refute
var buster = require('bustermove')

buster.testCase('maybeError called sync', {
'setUp': common.commonSetUp,
'tearDown': common.commonTearDown,

'put()': function (done) {
this.openTestDatabase(function (db) {
db.close(function () {
assert.isTrue(db.isClosed(), 'db is closed')
let sync = false
db.put('key', 'value', {}, function (err) {
sync = true
assert(err)
assert.equals(err.message, 'Database is not open')
})
assert.isFalse(sync, '.put cb called synchronously')
done()
})
})
},

'get()': function (done) {
this.openTestDatabase(function (db) {
db.put('key', 'value', {}, function (err) {
refute(err)
db.close(function () {
assert.isTrue(db.isClosed(), 'db is closed')
let sync = false
db.get('key', {}, function (err, value) {
sync = true
assert(err)
assert.equals(err.message, 'Database is not open')
})
assert.isFalse(sync, '.get cb called synchronously')
done()
})
})
})
},

'del()': function (done) {
this.openTestDatabase(function (db) {
db.put('key', 'value', {}, function (err) {
refute(err)
db.close(function () {
assert.isTrue(db.isClosed(), 'db is closed')
let sync = false
db.del('key', {}, function (err) {
sync = true
assert(err)
assert.equals(err.message, 'Database is not open')
})
assert.isFalse(sync, '.del cb called synchronously')
done()
})
})
})
},

'batch()': function (done) {
this.openTestDatabase(function (db) {
db.close(function () {
assert.isTrue(db.isClosed(), 'db is closed')
let sync = false
db.batch([{ type: 'put', key: 'key' }], {}, function (err) {
sync = true
assert(err)
assert.equals(err.message, 'Database is not open')
})
assert.isFalse(sync, '.batch cb called synchronously')
done()
})
})
}
})

0 comments on commit 1f8d697

Please sign in to comment.