Adding a test
This commit is contained in:
parent
ebf4f39331
commit
56b36ea063
|
@ -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',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue