Skip to content

Instantly share code, notes, and snippets.

@perjo927
Last active September 8, 2020 06:54
Show Gist options
  • Save perjo927/6a526d03765af7d304ddccbcebe1b1b4 to your computer and use it in GitHub Desktop.
Save perjo927/6a526d03765af7d304ddccbcebe1b1b4 to your computer and use it in GitHub Desktop.
import { makeStateHandlers } from "../src/redux/store/state.js";
import assert from "assert";
describe("state.js", () => {
describe("makeStateHandlers", () => {
it("generates two functions from a state container input", () => {
const stateContainer = [{ state: "state" }];
const stateHandlers = makeStateHandlers(stateContainer);
assert.equal(stateHandlers.hasOwnProperty("getState"), true);
assert.equal(stateHandlers.hasOwnProperty("setState"), true);
});
it("getState should return the last state", () => {
const stateContainer = [{ state: "state" }];
const stateHandlers = makeStateHandlers(stateContainer);
const expected = { state: "state" };
const actual = stateHandlers.getState();
assert.deepEqual(actual, expected);
});
it("setState should return the result of pushing a new item to the container", () => {
const stateContainer = [{ state: "state" }];
const newState = { state: "newState" };
const stateHandlers = makeStateHandlers(stateContainer);
const expectedContainer = [{ state: "state" }, { state: "newState" }];
const expectedLength = 2;
const actualLength = stateHandlers.setState(newState);
const actualContainer = stateContainer;
assert.equal(actualLength, expectedLength);
assert.deepEqual(actualContainer, expectedContainer);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment