Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
shoonia committed Feb 20, 2024
1 parent 1554ef9 commit 6a12063
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/on.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { randomUUID } from 'node:crypto';
import { jest } from '@jest/globals';
import { createStoreon } from '..';

describe('state.on()', () => {
it('should unsubscribe event listener', () => {
expect.hasAssertions();

const event = randomUUID();
const spy = jest.fn();

/** @type {Function} */
let off;

const { dispatch } = createStoreon([
(store) => {
off = store.on(event, spy);
},
]);

dispatch(event, '1');
off();
dispatch(event, '2');

expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith({}, '1');
});
});

0 comments on commit 6a12063

Please sign in to comment.