From 1be7498e0fe65fffeebf2d6203ad2bdbaf66a6e7 Mon Sep 17 00:00:00 2001 From: Mohamedox Date: Fri, 15 Mar 2019 11:31:42 +0100 Subject: [PATCH 1/5] reset state by effect --- src/new.spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/new.spec.js b/src/new.spec.js index 4cd43fa..498f3f5 100644 --- a/src/new.spec.js +++ b/src/new.spec.js @@ -288,5 +288,19 @@ describe("withStore", () => { }); return effects.foo(); }); + + it("can reset state", () => { + const { effects } = makeTestInstance({ + initialState: () => ({ qux: "qux" }), + effects: { + async foo() { + this.state.qux = "baz"; + this.resetState(); + expect(this.state.qux).toBe("qux"); + }, + }, + }); + return effects.foo(); + }); }); }); From b0bae913e36cd29e1f486f461a8cdb449bd0b2b9 Mon Sep 17 00:00:00 2001 From: Mohamedox Date: Fri, 15 Mar 2019 11:49:38 +0100 Subject: [PATCH 2/5] merge tests --- src/new.spec.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/new.spec.js b/src/new.spec.js index 498f3f5..1828eb8 100644 --- a/src/new.spec.js +++ b/src/new.spec.js @@ -259,6 +259,9 @@ describe("withStore", () => { expect(ownProps(this.effects)).toEqual(["myEffect", "_setState"]); expect(typeof this.resetState).toBe("function"); + this.state.myEntry = "thud"; + this.resetState(); + expect(this.state.myEntry).toBe("bar"); expect(ownProps(this.state)).toEqual(["myEntry"]); expect(this.state.myEntry).toBe("bar"); @@ -288,19 +291,5 @@ describe("withStore", () => { }); return effects.foo(); }); - - it("can reset state", () => { - const { effects } = makeTestInstance({ - initialState: () => ({ qux: "qux" }), - effects: { - async foo() { - this.state.qux = "baz"; - this.resetState(); - expect(this.state.qux).toBe("qux"); - }, - }, - }); - return effects.foo(); - }); }); }); From 99173b9b682d1b8dbfec9f6ed58be7ab0fcd4a3f Mon Sep 17 00:00:00 2001 From: Mohamedox Date: Fri, 15 Mar 2019 11:51:36 +0100 Subject: [PATCH 3/5] fix --- src/new.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/new.spec.js b/src/new.spec.js index 1828eb8..5dd1088 100644 --- a/src/new.spec.js +++ b/src/new.spec.js @@ -252,7 +252,7 @@ describe("withStore", () => { const { effects, getParentProps } = makeTestInstance({ initialState: () => ({ myEntry: "bar" }), effects: { - myEffect() { + async myEffect() { assert(isReadOnly(this)); assert(isReadOnly(this.effects)); @@ -260,7 +260,7 @@ describe("withStore", () => { expect(typeof this.resetState).toBe("function"); this.state.myEntry = "thud"; - this.resetState(); + await this.resetState(); expect(this.state.myEntry).toBe("bar"); expect(ownProps(this.state)).toEqual(["myEntry"]); From 344d70ef01a1106ee073c6bbb2943e17072e4581 Mon Sep 17 00:00:00 2001 From: Mohamedox Date: Fri, 15 Mar 2019 13:57:20 +0100 Subject: [PATCH 4/5] fix --- src/new.spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/new.spec.js b/src/new.spec.js index 5dd1088..f88550d 100644 --- a/src/new.spec.js +++ b/src/new.spec.js @@ -258,16 +258,16 @@ describe("withStore", () => { assert(isReadOnly(this.effects)); expect(ownProps(this.effects)).toEqual(["myEffect", "_setState"]); - expect(typeof this.resetState).toBe("function"); - this.state.myEntry = "thud"; - await this.resetState(); - expect(this.state.myEntry).toBe("bar"); - expect(ownProps(this.state)).toEqual(["myEntry"]); expect(this.state.myEntry).toBe("bar"); this.state.myEntry = "baz"; expect(this.state.myEntry).toBe("baz"); + expect(typeof this.resetState).toBe("function"); + this.state.myEntry = "thud"; + await this.resetState(); + expect(this.state.myEntry).toBe("bar"); + assert(isReadOnly(this.props)); expect(this.props).toBe(getParentProps()); }, From 6a10ab2be8522931913cb25be72c911f16595598 Mon Sep 17 00:00:00 2001 From: Mohamedox Date: Fri, 15 Mar 2019 15:04:29 +0100 Subject: [PATCH 5/5] fix --- src/new.spec.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/new.spec.js b/src/new.spec.js index f88550d..e96e4ce 100644 --- a/src/new.spec.js +++ b/src/new.spec.js @@ -263,8 +263,6 @@ describe("withStore", () => { this.state.myEntry = "baz"; expect(this.state.myEntry).toBe("baz"); - expect(typeof this.resetState).toBe("function"); - this.state.myEntry = "thud"; await this.resetState(); expect(this.state.myEntry).toBe("bar");