Skip to content

Commit

Permalink
failing test: getGlobalState in callback
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Jan 15, 2020
1 parent 5ddb0d6 commit 8565e67
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions __tests__/04_issue33_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ describe('issue #33 spec', () => {
const initialState = {
count1: 0,
};
let valueInCallback;
const { GlobalStateProvider, useGlobalState, getGlobalState } = createGlobalState(initialState);
const Counter = () => {
const [value, update] = useGlobalState('count1');
const onClick = () => {
update(value + 1);
valueInCallback = getGlobalState('count1');
};
return (
<div>
<span>{value}</span>
<button type="button" onClick={() => update(value + 1)}>+1</button>
<button type="button" onClick={onClick}>+1</button>
</div>
);
};
Expand All @@ -26,8 +31,11 @@ describe('issue #33 spec', () => {
</GlobalStateProvider>
);
const { getAllByText, container } = render(<App />);
expect(container.querySelector('span').textContent).toBe(String(getGlobalState('count1')));
expect(container.querySelector('span').textContent).toBe('0');
expect(getGlobalState('count1')).toBe(0);
fireEvent.click(getAllByText('+1')[0]);
expect(container.querySelector('span').textContent).toBe(String(getGlobalState('count1')));
expect(container.querySelector('span').textContent).toBe('1');
expect(getGlobalState('count1')).toBe(1);
expect(valueInCallback).toBe(1);
});
});

0 comments on commit 8565e67

Please sign in to comment.