This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ add failing tests for maybeError() and closed db
- Loading branch information
1 parent
98587eb
commit 1f8d697
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_levelup_test_db_61 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
} | ||
}) |