Skip to content

Commit 8b1b7f5

Browse files
author
Tom Saporito
committed
adds test
1 parent 662bdad commit 8b1b7f5

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"types": "dist/index.d.ts",
77
"scripts": {
88
"test": "node clean && npx rollup -c rollup.config.js && jest",
9+
"test:dev": "jest --watch",
910
"pre": "npm test && npm publish --tag next",
1011
"safe-publish": "npm test && npm publish"
1112
},

src/PubSub.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,10 @@ test("Emitting SPEAK should call shout and not whisper", () => {
5151
expect(shout.mock.calls.length).toBe(3);
5252
expect(whisper.mock.calls.length).toBe(2);
5353
});
54+
55+
test("emit without data contains empty object", () => {
56+
const mockFn = jest.fn((obj) => obj);
57+
pub.on("HELLO", mockFn);
58+
pub.emit("HELLO");
59+
expect(mockFn).toReturnWith({});
60+
});

src/PubSub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class PubSub {
2929
}
3030
}
3131

32-
emit(eventName: string, data?: object) {
32+
emit(eventName: string, data: object = {}) {
3333
if (this.events[eventName]) {
3434
this.events[eventName].forEach(function (fn) {
3535
fn(data);

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import PubSub from "./PubSub";
1111
const S: string = "UPDATE_STATE";
1212
const C: string = "CHANGE_STATE";
1313

14-
interface IAction {
14+
interface IAction extends Object {
1515
$type?: string;
1616
$deep?: boolean;
1717
[key: string]: any;

src/substate.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,18 @@ describe("ES5 version tests", () => {
130130
});
131131
expect(shallowStore.getCurrentState().a.b.c.d.e.f.name).toMatch("Danny");
132132
});
133+
134+
test("instance deep clone when passed reverts to false", () => {
135+
shallowStore.emit("UPDATE_STATE", {
136+
"a.b.c.d.e.f.name": "Charlie",
137+
});
138+
expect(shallowStore.getCurrentState().a.b.c.d.e.f.name).toMatch("Charlie");
139+
});
140+
141+
test("emit without data contains empty object", () => {
142+
const mockFn = jest.fn((obj) => obj);
143+
shallowStore.on("HELLO", mockFn);
144+
shallowStore.emit("HELLO");
145+
expect(mockFn).toReturnWith({});
146+
});
133147
});

0 commit comments

Comments
 (0)