Skip to content

Commit

Permalink
test(core): added event emitter test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Sep 8, 2021
1 parent b27b1b4 commit 6ff7abd
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion core/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
EventEmitter,
} from '../src/event-emitter';

import {
createStore,
} from '../src/index';
Expand Down Expand Up @@ -59,6 +63,31 @@ describe('Harlem Core', () => {
store = getStore();
});

describe('Event Emitter', () => {

test('Should handle on, once and emit', () => {
const eventEmitter = new EventEmitter();

const eventName = 'test-event';
const onListener = jest.fn();
const onceListener = jest.fn();

const listeners = [
eventEmitter.on(eventName, onListener),
eventEmitter.once(eventName, onceListener),
];

eventEmitter.emit(eventName);
eventEmitter.emit(eventName);

expect(onListener).toHaveBeenCalledTimes(2);
expect(onceListener).toHaveBeenCalledTimes(1);

listeners.forEach(({ dispose }) => dispose());
});

});

describe('Store', () => {

test('Should prevent duplicate creation of store objects', () => {
Expand Down Expand Up @@ -107,7 +136,7 @@ describe('Harlem Core', () => {
state,
} = store;

// @ts-expect-error
// @ts-expect-error This is readonly
state.firstName = 'Billy';

expect(state.firstName).toBe('John');
Expand Down

0 comments on commit 6ff7abd

Please sign in to comment.