mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-03 12:02:53 +00:00
test: prevent error from leaking
This commit is contained in:
@@ -22,20 +22,22 @@ import {StorageProvider} from './storage.provider';
|
||||
describe('StorageProvider', () => {
|
||||
let storageProvider: StorageProvider;
|
||||
let storage: Storage;
|
||||
let sampleEntries: Map<string, any>;
|
||||
|
||||
const sampleEntries: Map<string, any> = new Map([
|
||||
['foo', 'Bar'],
|
||||
['bar', {foo: 'BarFoo'} as any],
|
||||
['foo.bar', 123],
|
||||
]);
|
||||
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [StorageModule],
|
||||
providers: [StorageProvider],
|
||||
});
|
||||
storageProvider = TestBed.get(StorageProvider);
|
||||
storage = TestBed.get(Storage);
|
||||
|
||||
sampleEntries = new Map([
|
||||
['foo', 'Bar'],
|
||||
['bar', {foo: 'BarFoo'} as any],
|
||||
['foo.bar', 123],
|
||||
]);
|
||||
|
||||
spyOn(storage, 'forEach').and.callFake(function_ => {
|
||||
let i = 0;
|
||||
for (const key of sampleEntries.keys()) {
|
||||
@@ -48,23 +50,28 @@ describe('StorageProvider', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should call ready method of storage on init', () => {
|
||||
spyOn(storage, 'create');
|
||||
storageProvider.init();
|
||||
it('should call ready method of storage on init', async () => {
|
||||
// @ts-ignore
|
||||
spyOn(storage, 'create').and.callFake(() => Promise.resolve(undefined));
|
||||
await storageProvider.init();
|
||||
|
||||
expect(storage.create).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call set method of storage to put a value', () => {
|
||||
spyOn(storage, 'set');
|
||||
storageProvider.put('some-uid', {some: 'thing'});
|
||||
it('should call set method of storage to put a value', async () => {
|
||||
spyOn(storage, 'set').and.callFake(() => Promise.resolve());
|
||||
await storageProvider.put('some-uid', {some: 'thing'});
|
||||
|
||||
expect(storage.set).toHaveBeenCalledWith('some-uid', {some: 'thing'});
|
||||
});
|
||||
|
||||
it('should call get method of storage to get a value', () => {
|
||||
spyOn(storage, 'get');
|
||||
storageProvider.get('some-uid');
|
||||
it('should call get method of storage to get a value', async () => {
|
||||
spyOn(storage, 'get').and.callFake(() => Promise.resolve());
|
||||
try {
|
||||
await storageProvider.get('some-uid');
|
||||
}
|
||||
// if not caught, causes issues and tests fail
|
||||
catch {}
|
||||
|
||||
expect(storage.get).toHaveBeenCalledWith('some-uid');
|
||||
});
|
||||
@@ -100,7 +107,8 @@ describe('StorageProvider', () => {
|
||||
});
|
||||
|
||||
it('should put multiple values into the storage', async () => {
|
||||
spyOn(storageProvider, 'put');
|
||||
// @ts-ignore
|
||||
spyOn(storageProvider, 'put').and.callFake(() => Promise.resolve());
|
||||
await storageProvider.putMultiple(sampleEntries);
|
||||
|
||||
expect(storageProvider.put).toHaveBeenCalledTimes(sampleEntries.size);
|
||||
@@ -136,7 +144,7 @@ describe('StorageProvider', () => {
|
||||
});
|
||||
|
||||
it('should delete one or more entries from the storage', async () => {
|
||||
const storageRemoveSpy = spyOn(storage, 'remove');
|
||||
const storageRemoveSpy = spyOn(storage, 'remove').and.callFake(() => Promise.resolve());
|
||||
|
||||
await storageProvider.delete('bar');
|
||||
expect(storage.remove).toHaveBeenCalledTimes(1);
|
||||
@@ -148,7 +156,7 @@ describe('StorageProvider', () => {
|
||||
});
|
||||
|
||||
it('should delete all entries in the storage', async () => {
|
||||
spyOn(storage, 'clear');
|
||||
spyOn(storage, 'clear').and.callFake(() => Promise.resolve());
|
||||
|
||||
await storageProvider.deleteAll();
|
||||
expect(storage.clear).toHaveBeenCalled();
|
||||
|
||||
Reference in New Issue
Block a user