33const assert = require ( 'assert' ) ;
44const clear = require ( './clear' ) ;
55const Parse = require ( '../../node' ) ;
6+ const sleep = require ( './sleep' ) ;
67
78const TestObject = Parse . Object . extend ( 'TestObject' ) ;
89const DiffObject = Parse . Object . extend ( 'DiffObject' ) ;
@@ -15,7 +16,7 @@ describe('Parse LiveQuery', () => {
1516 clear ( ) . then ( done ) . catch ( done . fail ) ;
1617 } ) ;
1718
18- it ( 'can subscribe to query' , async ( ) => {
19+ it ( 'can subscribe to query' , async ( done ) => {
1920 const object = new TestObject ( ) ;
2021 await object . save ( ) ;
2122
@@ -25,12 +26,13 @@ describe('Parse LiveQuery', () => {
2526
2627 subscription . on ( 'update' , object => {
2728 assert . equal ( object . get ( 'foo' ) , 'bar' ) ;
29+ done ( ) ;
2830 } )
2931 object . set ( { foo : 'bar' } ) ;
3032 await object . save ( ) ;
3133 } ) ;
3234
33- it ( 'can subscribe to multiple queries' , async ( done ) => {
35+ it ( 'can subscribe to multiple queries' , async ( ) => {
3436 const objectA = new TestObject ( ) ;
3537 const objectB = new TestObject ( ) ;
3638 await Parse . Object . saveAll ( [ objectA , objectB ] ) ;
@@ -52,14 +54,11 @@ describe('Parse LiveQuery', () => {
5254 } )
5355 await objectA . save ( { foo : 'bar' } ) ;
5456 await objectB . save ( { foo : 'baz' } ) ;
55-
56- setTimeout ( ( ) => {
57- assert . equal ( count , 2 ) ;
58- done ( ) ;
59- } , 100 ) ;
57+ await sleep ( 1000 ) ;
58+ assert . equal ( count , 2 ) ;
6059 } ) ;
6160
62- it ( 'can subscribe to multiple queries different class' , async ( done ) => {
61+ it ( 'can subscribe to multiple queries different class' , async ( ) => {
6362 const objectA = new TestObject ( ) ;
6463 const objectB = new DiffObject ( ) ;
6564 await Parse . Object . saveAll ( [ objectA , objectB ] ) ;
@@ -81,14 +80,11 @@ describe('Parse LiveQuery', () => {
8180 } )
8281 await objectA . save ( { foo : 'bar' } ) ;
8382 await objectB . save ( { foo : 'baz' } ) ;
84-
85- setTimeout ( ( ) => {
86- expect ( count ) . toBe ( 2 ) ;
87- done ( ) ;
88- } , 1000 ) ;
83+ await sleep ( 1000 ) ;
84+ assert . equal ( count , 2 ) ;
8985 } ) ;
9086
91- it ( 'can unsubscribe to multiple queries different class' , async ( done ) => {
87+ it ( 'can unsubscribe to multiple queries different class' , async ( ) => {
9288 const objectA = new TestObject ( ) ;
9389 const objectB = new DiffObject ( ) ;
9490 await Parse . Object . saveAll ( [ objectA , objectB ] ) ;
@@ -110,14 +106,11 @@ describe('Parse LiveQuery', () => {
110106 subscriptionA . unsubscribe ( ) ;
111107 await objectA . save ( { foo : 'bar' } ) ;
112108 await objectB . save ( { foo : 'baz' } ) ;
113-
114- setTimeout ( ( ) => {
115- assert . equal ( count , 1 ) ;
116- done ( ) ;
117- } , 1000 ) ;
109+ await sleep ( 1000 ) ;
110+ assert . equal ( count , 1 ) ;
118111 } ) ;
119112
120- it ( 'can unsubscribe with await to multiple queries different class' , async ( done ) => {
113+ it ( 'can unsubscribe with await to multiple queries different class' , async ( ) => {
121114 const objectA = new TestObject ( ) ;
122115 const objectB = new DiffObject ( ) ;
123116 await Parse . Object . saveAll ( [ objectA , objectB ] ) ;
@@ -139,10 +132,7 @@ describe('Parse LiveQuery', () => {
139132 await subscriptionA . unsubscribe ( ) ;
140133 await objectA . save ( { foo : 'bar' } ) ;
141134 await objectB . save ( { foo : 'baz' } ) ;
142-
143- setTimeout ( ( ) => {
144- assert . equal ( count , 1 ) ;
145- done ( ) ;
146- } , 1000 ) ;
135+ await sleep ( 1000 ) ;
136+ assert . equal ( count , 1 ) ;
147137 } ) ;
148138} ) ;
0 commit comments