diff --git a/src/new.spec.js b/src/new.spec.js index 6f4d90e..d77cd03 100644 --- a/src/new.spec.js +++ b/src/new.spec.js @@ -4,6 +4,7 @@ const assert = require("assert"); const { createElement } = require("react"); const { configure, mount } = require("enzyme"); +const CircularComputedError = require("./_CircularComputedError"); const { withStore } = require("./"); configure({ adapter: new (require("enzyme-adapter-react-16"))() }); @@ -92,24 +93,41 @@ describe("withStore", () => { }); describe("computed", () => { - it("receive read-only state", () => { + it("receive read-only state and props", () => { + const props = { qux: "qux" }; + const { getState } = makeTestInstance( + { + initialState: () => ({ + foo: "foo", + }), + computed: { + bar: () => "bar", + baz(state, props) { + assert(isReadOnly(state)); + assert(isReadOnly(props)); + + expect(state.foo).toBe("foo"); + expect(state.bar).toBe("bar"); + expect(props.qux).toBe("qux"); + + return "baz"; + }, + }, + }, + props + ); + + expect(getState().baz).toBe("baz"); + }); + + it("cannot access itself", () => { const { getState } = makeTestInstance({ - initialState: () => ({ - foo: "foo", - }), computed: { - bar: () => "bar", - baz(state) { - assert(isReadOnly(state)); - expect(state.foo).toBe("foo"); - expect(state.bar).toBe("bar"); - - return "baz"; - }, + circular: ({ circular }) => {}, }, }); - expect(getState().baz).toBe("baz"); + expect(() => getState().circular).toThrow(CircularComputedError); }); }); });