Skip to content

Commit

Permalink
adds test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Saporito committed Sep 3, 2020
1 parent 662bdad commit 8b1b7f5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"types": "dist/index.d.ts",
"scripts": {
"test": "node clean && npx rollup -c rollup.config.js && jest",
"test:dev": "jest --watch",
"pre": "npm test && npm publish --tag next",
"safe-publish": "npm test && npm publish"
},
Expand Down
7 changes: 7 additions & 0 deletions src/PubSub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ test("Emitting SPEAK should call shout and not whisper", () => {
expect(shout.mock.calls.length).toBe(3);
expect(whisper.mock.calls.length).toBe(2);
});

test("emit without data contains empty object", () => {
const mockFn = jest.fn((obj) => obj);
pub.on("HELLO", mockFn);
pub.emit("HELLO");
expect(mockFn).toReturnWith({});
});
2 changes: 1 addition & 1 deletion src/PubSub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class PubSub {
}
}

emit(eventName: string, data?: object) {
emit(eventName: string, data: object = {}) {
if (this.events[eventName]) {
this.events[eventName].forEach(function (fn) {
fn(data);
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PubSub from "./PubSub";
const S: string = "UPDATE_STATE";
const C: string = "CHANGE_STATE";

interface IAction {
interface IAction extends Object {
$type?: string;
$deep?: boolean;
[key: string]: any;
Expand Down
14 changes: 14 additions & 0 deletions src/substate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,18 @@ describe("ES5 version tests", () => {
});
expect(shallowStore.getCurrentState().a.b.c.d.e.f.name).toMatch("Danny");
});

test("instance deep clone when passed reverts to false", () => {
shallowStore.emit("UPDATE_STATE", {
"a.b.c.d.e.f.name": "Charlie",
});
expect(shallowStore.getCurrentState().a.b.c.d.e.f.name).toMatch("Charlie");
});

test("emit without data contains empty object", () => {
const mockFn = jest.fn((obj) => obj);
shallowStore.on("HELLO", mockFn);
shallowStore.emit("HELLO");
expect(mockFn).toReturnWith({});
});
});

0 comments on commit 8b1b7f5

Please sign in to comment.