1
- import { assert , JSData } from '../../_setup'
1
+ import { assert , JSData , sinon } from '../../_setup'
2
2
3
3
describe ( 'Record#hasChanges' , function ( ) {
4
4
it ( 'should be an instance method' , function ( ) {
@@ -13,7 +13,7 @@ describe('Record#hasChanges', function () {
13
13
post . author = 'Jake'
14
14
assert ( post . hasChanges ( ) )
15
15
} )
16
- it ( 'should return true if a tracked field is changed' , function ( ) {
16
+ it ( 'should return true if a tracked field is changed' , function ( done ) {
17
17
const PostMapper = new JSData . Mapper ( {
18
18
name : 'post' ,
19
19
schema : {
@@ -26,10 +26,45 @@ describe('Record#hasChanges', function () {
26
26
}
27
27
} )
28
28
const post = PostMapper . createRecord ( this . data . p1 )
29
+ const listener = sinon . stub ( )
30
+ post . on ( 'change' , listener )
29
31
assert ( ! post . hasChanges ( ) )
30
32
post . author = 'Jake'
31
33
assert ( post . hasChanges ( ) )
32
34
post . author = 'John'
33
35
assert ( ! post . hasChanges ( ) )
36
+ setTimeout ( function ( ) {
37
+ assert . equal ( listener . callCount , 0 )
38
+ done ( )
39
+ } , 5 )
40
+ } ) ,
41
+
42
+ it ( 'is not affected by timing' , function ( done ) {
43
+ const PostMapper = new JSData . Mapper ( {
44
+ name : 'post' ,
45
+ schema : {
46
+ properties : {
47
+ author : {
48
+ type : 'string' ,
49
+ track : true
50
+ }
51
+ }
52
+ }
53
+ } )
54
+ const post = PostMapper . createRecord ( this . data . p1 )
55
+ const listener = sinon . stub ( )
56
+ post . on ( 'change' , listener )
57
+ post . author = 'Jake'
58
+ assert ( post . hasChanges ( ) )
59
+ const secondSpec = function ( ) {
60
+ assert . equal ( listener . callCount , 2 )
61
+ assert ( ! post . hasChanges ( ) )
62
+ done ( )
63
+ }
64
+ setTimeout ( function ( ) {
65
+ assert . equal ( listener . callCount , 1 )
66
+ post . author = 'John'
67
+ setTimeout ( secondSpec , 5 )
68
+ } , 5 )
34
69
} )
35
70
} )
0 commit comments