ngx-indexed-db icon indicating copy to clipboard operation
ngx-indexed-db copied to clipboard

Add testing module to handle mocking the indexedDb and easily fetching the info for assertions in unit tests

Open sbordeyne opened this issue 2 years ago • 1 comments

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.

sbordeyne avatar Jan 02 '23 18:01 sbordeyne

We are mocking indexedDb and just spy function if it called;

mockIndexedDBSpy = jasmine.createSpyObj('indexedDB', ['add', 'clear', 'count', 'delete', 'getAll', 'getByKey', 'update']);

yasinkocak avatar Nov 02 '23 07:11 yasinkocak