@@ -9,12 +9,12 @@ import {
9
9
import { MangoQuery , RxQuery } from 'rxdb' ;
10
10
import { createRxLocalDocument } from 'rxdb/plugins/local-documents' ;
11
11
import { RxReplicationState } from 'rxdb/plugins/replication' ;
12
- import { EMPTY , Observable , Subject , firstValueFrom } from 'rxjs' ;
12
+ import { EMPTY , Observable , Subject , firstValueFrom , of } from 'rxjs' ;
13
13
import {
14
14
NgxRxdbCollection ,
15
15
NgxRxdbCollectionService ,
16
16
collectionServiceFactory ,
17
- } from './rxdb- collection.service' ;
17
+ } from './collection.service' ;
18
18
19
19
const getMockReplicationState = ( obj : Partial < RxReplicationState < any , any > > ) => {
20
20
obj . reSync = jest . fn ( ) ;
@@ -75,15 +75,6 @@ describe(`NgxRxdbCollectionService`, () => {
75
75
expect ( service . collection ) . toBeDefined ( ) ;
76
76
} ) ;
77
77
78
- it ( 'should throw an error if collection is not initialized and initialized$ rejects' , async ( ) => {
79
- service [ '_collection' ] = null as any ;
80
- service [ '_init$' ] = new Subject ( ) as any ;
81
- service [ '_init$' ] . complete ( ) ;
82
- await expect ( service [ 'ensureCollection' ] ( ) ) . rejects . toThrow (
83
- `Collection "${ service . config . name } " was not initialized. Please check previous RxDB errors.`
84
- ) ;
85
- } ) ;
86
-
87
78
it ( 'should destroy collection' , async ( ) => {
88
79
jest . spyOn ( service . collection , 'destroy' ) . mockResolvedValue ( null as any ) ;
89
80
await service . destroy ( ) ;
@@ -96,14 +87,23 @@ describe(`NgxRxdbCollectionService`, () => {
96
87
expect ( service . collection . remove ) . toHaveBeenCalled ( ) ;
97
88
} ) ;
98
89
99
- it ( 'should call ensureCollection ' , async ( ) => {
90
+ it ( 'should always ensure collection is created asynchronously before calling any method (e.g. `info`) ' , async ( ) => {
100
91
const spy = jest
101
- . spyOn ( service as any , 'ensureCollection ' )
102
- . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
103
- await service . sync ( ) ;
92
+ . spyOn ( service , 'initialized$' , 'get ' )
93
+ . mockImplementation ( ( ) => of ( true ) ) ;
94
+ await service . info ( ) ;
104
95
expect ( spy ) . toHaveBeenCalled ( ) ;
105
96
} ) ;
106
97
98
+ it ( 'should throw an error if collection is not initialized and initialized$ rejects' , async ( ) => {
99
+ service [ '_collection' ] = null as any ;
100
+ service [ '_init$' ] = new Subject ( ) as any ;
101
+ service [ '_init$' ] . complete ( ) ;
102
+ await expect ( service . info ( ) ) . rejects . toThrow (
103
+ `Collection "${ service . config . name } " was not initialized. Please check RxDB errors.`
104
+ ) ;
105
+ } ) ;
106
+
107
107
it ( 'should handle valid replicationState' , async ( ) => {
108
108
service . config . options = {
109
109
...service . config . options ,
0 commit comments