Skip to content

Commit 5d00030

Browse files
committed
1 parent fc6f742 commit 5d00030

File tree

5 files changed

+45
-1164
lines changed

5 files changed

+45
-1164
lines changed

tests/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require('./specs/constructor')
22
require('./specs/api')
33
require('./specs/sync')
4-
require('./specs/scoped')
54
require('./specs/is-persistent')

tests/specs/api.js

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var PouchDB = require('../utils/pouchdb.js')
55
var Store = require('../../')
66

77
test('API methods', function (t) {
8-
t.plan(12)
8+
t.plan(13)
99

1010
var store = new Store('test-db-api', {
1111
PouchDB: PouchDB,
@@ -24,29 +24,26 @@ test('API methods', function (t) {
2424
t.is(typeof store.on, 'function', 'has "on" method')
2525
t.is(typeof store.one, 'function', 'has "one" method')
2626
t.is(typeof store.off, 'function', 'has "off" method')
27+
t.is(typeof store.withIdPrefix, 'function', 'has "withIdPrefix" method')
2728
})
2829

2930
test('store.on("change") with adding one', function (t) {
30-
t.plan(3)
31+
t.plan(2)
3132

3233
var store = new Store('test-db-change', {
3334
PouchDB: PouchDB,
3435
remote: 'test-db-change'
3536
})
36-
var changeEvents = []
3737

38-
store.on('change', addEventToArray.bind(null, changeEvents))
38+
store.on('change', function (eventName, doc) {
39+
t.is(eventName, 'add', 'passes the event name')
40+
t.is(doc.foo, 'bar', 'event passes object')
41+
})
3942

4043
store.add({
4144
foo: 'bar'
4245
})
4346

44-
.then(function () {
45-
t.is(changeEvents.length, 1, 'triggers 1 change event')
46-
t.is(changeEvents[0].eventName, 'add', 'passes the event name')
47-
t.is(changeEvents[0].object.foo, 'bar', 'event passes object')
48-
})
49-
5047
.catch(t.fail)
5148
})
5249

@@ -80,38 +77,39 @@ test('store.off("add") with one add handler', function (t) {
8077
})
8178

8279
test('store.one("add") with adding one', function (t) {
83-
t.plan(2)
80+
t.plan(1)
8481

8582
var store = new Store('test-db-one', {
8683
PouchDB: PouchDB,
8784
remote: 'test-db-one'
8885
})
89-
var addEvents = []
9086

91-
store.one('add', addEventToArray.bind(null, addEvents))
87+
store.one('add', function (doc) {
88+
t.is(doc.foo, 'bar', 'event passes object')
89+
})
9290

9391
store.add({
9492
foo: 'bar'
9593
})
9694

97-
.then(function () {
98-
t.is(addEvents.length, 1, 'triggers 1 add event')
99-
t.is(addEvents[0].object.foo, 'bar', 'event passes object')
100-
})
101-
10295
.catch(t.fail)
10396
})
10497

10598
test('store.reset creates empty instance of store', function (t) {
106-
t.plan(3)
99+
t.plan(2)
107100

108101
var store = new Store('test-db-clear', {
109102
PouchDB: PouchDB,
110103
remote: 'test-db-clear'
111104
})
112-
var addEvents = []
113-
store.on('add', addEvents.push.bind(addEvents))
114-
store.on('clear', t.pass.bind(null, '"clear" event emitted'))
105+
var clearTriggered = false
106+
store.on('add', function (doc) {
107+
t.ok(clearTriggered, 'triggers "add" event after "clear"')
108+
})
109+
store.on('clear', function () {
110+
clearTriggered = true
111+
t.pass('"clear" event emitted')
112+
})
115113
store.reset()
116114

117115
.then(function () {
@@ -124,10 +122,6 @@ test('store.reset creates empty instance of store', function (t) {
124122
return store.add({id: 'test', foo: 'bar'})
125123
})
126124

127-
.then(function () {
128-
t.is(addEvents.length, 1, 'triggers "add" event after "clear"')
129-
})
130-
131125
.catch(t.fail)
132126
})
133127

tests/specs/constructor.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ test('new Store(db, options)', function (t) {
1010
remote: 'test-db-remote'
1111
}))
1212

13-
t.is(typeof store, 'function', 'is a constructor')
1413
t.ok(store.db, 'sets .db on instance')
1514
t.is(store.db.name, 'test-db', '.db is PouchDB object')
1615

@@ -23,7 +22,6 @@ test('Store(db, options) w/o new', function (t) {
2322
remote: 'test-db-remote'
2423
})
2524

26-
t.is(typeof store, 'function', 'is a constructor')
2725
t.ok(store.db, 'sets .db on instance')
2826
t.is(store.db.name, 'test-db', '.db is PouchDB object')
2927

0 commit comments

Comments
 (0)