Adding a test

This commit is contained in:
Eric van der Vlist 2022-11-07 12:01:58 +01:00
parent ebf4f39331
commit 56b36ea063
1 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,9 @@
import worker from './dispatcher-worker';
jest.mock('../db', () => ({
initDb: () => 'called initDb',
}));
describe('The dispatcher-worker ', () => {
let port;
beforeEach(() => {
@ -12,11 +16,18 @@ describe('The dispatcher-worker ', () => {
expect(port.onmessage).toBeDefined();
expect(port.postMessage).not.toBeCalled();
});
test('receives a ping and sends a pong', () => {
port.onmessage({ data: { id: 5, payload: 'ping' } });
test('receives a ping and sends back an unknownAction', () => {
port.onmessage({ data: { id: 5, payload: { action: 'ping' } } });
expect(port.postMessage).toBeCalledWith({
id: 5,
payload: 'unknownAction',
});
});
test('calls initDb when required', async () => {
await port.onmessage({ data: { id: 5, payload: { action: 'initDb' } } });
expect(port.postMessage).toBeCalledWith({
id: 5,
payload: 'called initDb',
});
});
});