Last active
September 8, 2020 06:54
-
-
Save perjo927/6a526d03765af7d304ddccbcebe1b1b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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