@@ -5,7 +5,7 @@ var PouchDB = require('../utils/pouchdb.js')
5
5
var Store = require ( '../../' )
6
6
7
7
test ( 'API methods' , function ( t ) {
8
- t . plan ( 12 )
8
+ t . plan ( 13 )
9
9
10
10
var store = new Store ( 'test-db-api' , {
11
11
PouchDB : PouchDB ,
@@ -24,29 +24,26 @@ test('API methods', function (t) {
24
24
t . is ( typeof store . on , 'function' , 'has "on" method' )
25
25
t . is ( typeof store . one , 'function' , 'has "one" method' )
26
26
t . is ( typeof store . off , 'function' , 'has "off" method' )
27
+ t . is ( typeof store . withIdPrefix , 'function' , 'has "withIdPrefix" method' )
27
28
} )
28
29
29
30
test ( 'store.on("change") with adding one' , function ( t ) {
30
- t . plan ( 3 )
31
+ t . plan ( 2 )
31
32
32
33
var store = new Store ( 'test-db-change' , {
33
34
PouchDB : PouchDB ,
34
35
remote : 'test-db-change'
35
36
} )
36
- var changeEvents = [ ]
37
37
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
+ } )
39
42
40
43
store . add ( {
41
44
foo : 'bar'
42
45
} )
43
46
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
-
50
47
. catch ( t . fail )
51
48
} )
52
49
@@ -80,38 +77,39 @@ test('store.off("add") with one add handler', function (t) {
80
77
} )
81
78
82
79
test ( 'store.one("add") with adding one' , function ( t ) {
83
- t . plan ( 2 )
80
+ t . plan ( 1 )
84
81
85
82
var store = new Store ( 'test-db-one' , {
86
83
PouchDB : PouchDB ,
87
84
remote : 'test-db-one'
88
85
} )
89
- var addEvents = [ ]
90
86
91
- store . one ( 'add' , addEventToArray . bind ( null , addEvents ) )
87
+ store . one ( 'add' , function ( doc ) {
88
+ t . is ( doc . foo , 'bar' , 'event passes object' )
89
+ } )
92
90
93
91
store . add ( {
94
92
foo : 'bar'
95
93
} )
96
94
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
-
102
95
. catch ( t . fail )
103
96
} )
104
97
105
98
test ( 'store.reset creates empty instance of store' , function ( t ) {
106
- t . plan ( 3 )
99
+ t . plan ( 2 )
107
100
108
101
var store = new Store ( 'test-db-clear' , {
109
102
PouchDB : PouchDB ,
110
103
remote : 'test-db-clear'
111
104
} )
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
+ } )
115
113
store . reset ( )
116
114
117
115
. then ( function ( ) {
@@ -124,10 +122,6 @@ test('store.reset creates empty instance of store', function (t) {
124
122
return store . add ( { id : 'test' , foo : 'bar' } )
125
123
} )
126
124
127
- . then ( function ( ) {
128
- t . is ( addEvents . length , 1 , 'triggers "add" event after "clear"' )
129
- } )
130
-
131
125
. catch ( t . fail )
132
126
} )
133
127
0 commit comments