Skip to content

Commit

Permalink
update failing test to match the use case in #33
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Jan 16, 2020
1 parent 8565e67 commit 0d2645a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions __tests__/04_issue33_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ describe('issue #33 spec', () => {
const initialState = {
count1: 0,
};
let valueInCallback;
const { GlobalStateProvider, useGlobalState, getGlobalState } = createGlobalState(initialState);
const Positive = ({ count }) => {
if (count !== getGlobalState('count1')) throw Error('count mismatch');
return <div>{count} is positive</div>;
};
const Counter = () => {
const [value, update] = useGlobalState('count1');
const onClick = () => {
update(value + 1);
valueInCallback = getGlobalState('count1');
};
return (
<div>
<span>{value}</span>
<button type="button" onClick={onClick}>+1</button>
<button type="button" onClick={() => update(value + 1)}>+1</button>
{value > 0 && <Positive count={value} />}
</div>
);
};
Expand All @@ -36,6 +36,5 @@ describe('issue #33 spec', () => {
fireEvent.click(getAllByText('+1')[0]);
expect(container.querySelector('span').textContent).toBe('1');
expect(getGlobalState('count1')).toBe(1);
expect(valueInCallback).toBe(1);
});
});

0 comments on commit 0d2645a

Please sign in to comment.