Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shoonia committed Feb 20, 2024
1 parent 6a12063 commit 5b227e8
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 39 deletions.
4 changes: 2 additions & 2 deletions tests/@init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('@init event', () => {

readyStore();

expect(getState()).toEqual({ a: 0 });
expect(getState()).toStrictEqual({ a: 0 });
});

it('should run initial connect', (done) => {
Expand All @@ -26,7 +26,7 @@ describe('@init event', () => {
]);

connect('b', (state) => {
expect(state).toEqual({ b: 1 });
expect(state).toStrictEqual({ b: 1 });
done();
});

Expand Down
8 changes: 4 additions & 4 deletions tests/@ready.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('@ready event', () => {
const { readyStore } = createStoreon([
(store) => {
store.on('@ready', (state) => {
expect(state).toEqual({});
expect(state).toStrictEqual({});
done();
});
},
Expand All @@ -23,7 +23,7 @@ describe('@ready event', () => {
(store) => {
store.on('@init', () => ({ xyz: true }));
store.on('@ready', (state) => {
expect(state).toEqual({ xyz: true });
expect(state).toStrictEqual({ xyz: true });
done();
});
},
Expand All @@ -42,7 +42,7 @@ describe('@ready event', () => {
]);

connect('some', (state) => {
expect(state).toEqual({ some: [] });
expect(state).toStrictEqual({ some: [] });
done();
});

Expand All @@ -61,7 +61,7 @@ describe('@ready event', () => {
]);

connect('one', 'two', (state) => {
expect(state).toEqual({ one: 'one', two: 'two' });
expect(state).toStrictEqual({ one: 'one', two: 'two' });
done();
});

Expand Down
10 changes: 5 additions & 5 deletions tests/@set.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('@set event', () => {
]);

connect((state) => {
expect(state).toEqual({ a: 5, b: 0 });
expect(getState()).toEqual({ a: 5, b: 0 });
expect(state).toStrictEqual({ a: 5, b: 0 });
expect(getState()).toStrictEqual({ a: 5, b: 0 });
done();
});

Expand All @@ -44,8 +44,8 @@ describe('@set event', () => {
readyStore();

connect('i', (state) => {
expect(state).toEqual({ i: 5, p: null });
expect(getState()).toEqual({ i: 5, p: null });
expect(state).toStrictEqual({ i: 5, p: null });
expect(getState()).toStrictEqual({ i: 5, p: null });
done();
});

Expand All @@ -63,6 +63,6 @@ describe('@set event', () => {

dispatch('@set', { x: 9 });

expect(getState()).toEqual({ x: 9, y: 0 });
expect(getState()).toStrictEqual({ x: 9, y: 0 });
});
});
21 changes: 9 additions & 12 deletions tests/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('connect method', () => {
const { connect, readyStore } = createStoreon([]);

connect(/* no key */(state) => {
expect(state).toEqual({});
expect(state).toStrictEqual({});
done();
});

Expand All @@ -23,7 +23,7 @@ describe('connect method', () => {

// eslint-disable-next-line require-await
connect(async (state) => {
expect(state).toEqual({});
expect(state).toStrictEqual({});
done();
});

Expand All @@ -36,7 +36,7 @@ describe('connect method', () => {
const { connect, readyStore } = createStoreon([]);

connect(randomUUID(), (state) => {
expect(state).toEqual({});
expect(state).toStrictEqual({});
done();
});

Expand All @@ -55,17 +55,14 @@ describe('connect method', () => {
(store) => {
store.on(eventX, (_, x) => ({ x }));
store.on(eventY, (_, y) => ({ y }));

store.on('@ready', (state) => {
spy(state);
});
store.on('@ready', spy);
},
]);

connect('x', (state) => {
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith({ x: 2, y: 4 });
expect(state).toEqual({ x: 2, y: 4 });
expect(spy).toHaveBeenCalledWith({ x: 2, y: 4 }, undefined);
expect(state).toStrictEqual({ x: 2, y: 4 });
done();
});

Expand Down Expand Up @@ -147,14 +144,14 @@ describe('connect method', () => {

store.on('@ready', (state) => {
spy();
expect(state).toEqual({ i: 0 });
expect(state).toStrictEqual({ i: 0 });
return { i: 1 };
});
},
]);

connect('i', (state) => {
expect(state).toEqual({ i: 1 });
expect(state).toStrictEqual({ i: 1 });
expect(spy).toHaveBeenCalledTimes(2);
done();
});
Expand Down Expand Up @@ -187,7 +184,7 @@ describe('connect method', () => {
dispatch(event);

connect('t', (state) => {
expect(state).toEqual({ t: 2 });
expect(state).toStrictEqual({ t: 2 });
expect(spy).toHaveBeenCalledTimes(2);
done();
});
Expand Down
16 changes: 7 additions & 9 deletions tests/dispatch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ describe('dispatch method', () => {

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

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

expect(spy).toHaveBeenCalledTimes(2);
expect(spy).toHaveBeenNthCalledWith(1, {}, 1);
expect(spy).toHaveBeenNthCalledWith(2, {}, 2);
});

it('should post the data to the event listener', () => {
Expand All @@ -31,15 +31,13 @@ describe('dispatch method', () => {

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

dispatch(event, { data: {} });

expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith({ data: {} });
expect(spy).toHaveBeenCalledWith({}, { data: {} });
});
});
6 changes: 3 additions & 3 deletions tests/getState.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ describe('getState method', () => {
},
]);

expect(getState()).toEqual({});
expect(getState()).toStrictEqual({});
dispatch(event, 1);
expect(getState()).toEqual({ x: 1 });
expect(getState()).toStrictEqual({ x: 1 });
dispatch(event, 2);
expect(getState()).toEqual({ x: 2 });
expect(getState()).toStrictEqual({ x: 2 });
});

it('should equal data in all methods', (done) => {
Expand Down
2 changes: 2 additions & 0 deletions tests/multi-keys.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('Multi keys', () => {
dispatch(eventTwo, 1);

expect(cb).toHaveBeenCalledTimes(2);
expect(cb).toHaveBeenNthCalledWith(1, { x: 1 });
expect(cb).toHaveBeenNthCalledWith(2, { x: 1, y: 1 });
});

it('should run one time of change two properties synchronic', () => {
Expand Down
8 changes: 4 additions & 4 deletions tests/setState.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('getState method', () => {

setState({ x: 1 });

expect(getState()).toEqual({ x: 1, y: 0 });
expect(getState()).toStrictEqual({ x: 1, y: 0 });
});

it('should add new property to state', () => {
Expand All @@ -26,7 +26,7 @@ describe('getState method', () => {

setState({ b: 20 });

expect(getState()).toEqual({ a: 10, b: 20 });
expect(getState()).toStrictEqual({ a: 10, b: 20 });
});

it('should fire on @set event', (done) => {
Expand All @@ -36,8 +36,8 @@ describe('getState method', () => {
(store) => {
store.on('@init', () => ({ a: 1, b: 0 }));
store.on('@set', (state, changes) => {
expect(state).toEqual({ a: 1, b: 1 });
expect(changes).toEqual({ b: 1 });
expect(state).toStrictEqual({ a: 1, b: 1 });
expect(changes).toStrictEqual({ b: 1 });
done();
});
},
Expand Down

0 comments on commit 5b227e8

Please sign in to comment.