Skip to content

Commit 67f22a7

Browse files
authored
Fix <Counter /> set handler (#115)
Fixes #114 I added a couple of tests to prevent this later.
1 parent 471c57a commit 67f22a7

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

.size-snapshot.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"dist/react-powerplug.umd.js": {
3-
"bundled": 23340,
4-
"minified": 9379,
5-
"gzipped": 2578
3+
"bundled": 23769,
4+
"minified": 9469,
5+
"gzipped": 2596
66
},
77
"dist/react-powerplug.cjs.js": {
8-
"bundled": 20442,
9-
"minified": 10525,
10-
"gzipped": 2470
8+
"bundled": 20833,
9+
"minified": 10881,
10+
"gzipped": 2485
1111
},
1212
"dist/react-powerplug.esm.js": {
13-
"bundled": 19780,
14-
"minified": 9965,
15-
"gzipped": 2334,
13+
"bundled": 20171,
14+
"minified": 10321,
15+
"gzipped": 2348,
1616
"treeshaked": {
1717
"rollup": {
1818
"code": 365,

src/components/Counter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Counter = ({ initial = 0, onChange, ...props }) => (
2020
dec: () => setState(add(-1)),
2121
incBy: value => setState(add(value)),
2222
decBy: value => setState(add(-value)),
23-
set: value => setState(s => ({ on: set(value, s.on) })),
23+
set: value => setState(s => ({ count: set(value, s.count) })),
2424
})
2525
}
2626
</State>

tests/components/Counter.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ test('<Counter />', () => {
2121

2222
lastCallArg(renderFn).decBy(3)
2323
expect(renderFn).lastCalledWith(expect.objectContaining({ count: 2 }))
24+
25+
lastCallArg(renderFn).set(10)
26+
expect(renderFn).lastCalledWith(expect.objectContaining({ count: 10 }))
27+
28+
lastCallArg(renderFn).set(count => count + 10)
29+
expect(renderFn).lastCalledWith(expect.objectContaining({ count: 20 }))
2430
})
2531

2632
test('<Counter onChange />', () => {

0 commit comments

Comments
 (0)