Skip to content

Instantly share code, notes, and snippets.

@perjo927
Created September 8, 2020 07:27
Show Gist options
  • Save perjo927/3544c5506a19a5c43a25e4fdfb39ae93 to your computer and use it in GitHub Desktop.
Save perjo927/3544c5506a19a5c43a25e4fdfb39ae93 to your computer and use it in GitHub Desktop.
Test subscriber
import { makeSubscriber } from "../src/redux/store/subscribe.js";
import assert from "assert";
describe("subscribe.js", () => {
describe("makeSubscriber", () => {
it("generates a function from subscribers", () => {
const subscribers = [];
const subscriber = makeSubscriber(subscribers);
assert.equal(subscriber.hasOwnProperty("subscribe"), true);
});
it("calls the subscriber", () => {
const subscribers = [];
const spyOnSubscribe = { called: false };
const { subscribe } = makeSubscriber(subscribers);
subscribe(() => (spyOnSubscribe.called = true));
subscribers.forEach((subscription) => subscription());
const expected = true;
const actual = spyOnSubscribe.called;
assert.equal(actual, expected);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment