ngx-indexed-db
ngx-indexed-db copied to clipboard
Add testing module to handle mocking the indexedDb and easily fetching the info for assertions in unit tests
Hello, first of all thanks for the library.
I've found myself using this library, and I'm lacking the ability to easily test the contents of the indexed Db, unless I'm doing something wrong ?
Here's my setup :
describe('Suite', () => {
let service: MyService;
let indexedDb: NgxIndexedDBService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [NgxIndexedDBModule.forRoot(dbConfig)],
providers: [{ provide: PLATFORM_ID, useValue: 'browser' }],
});
service = TestBed.inject(MyService);
indexedDb = TestBed.inject(NgxIndexedDBService);
});
it('should work', () => {
service.foo().subscribe((value) => {
indexedDb.getByKey('store', value.id).subscribe((result) => expect(result.id).toBe(value.id));
});
});
});
Obviously, the example is minimal, but I can't get it to work as expected. Any help, or support for unit testing from the library itself would be greatly appreciated.
We are mocking indexedDb
and just spy function if it called;
mockIndexedDBSpy = jasmine.createSpyObj('indexedDB', ['add', 'clear', 'count', 'delete', 'getAll', 'getByKey', 'update']);