Skip to content

Commit

Permalink
test for #33
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Jan 15, 2020
1 parent 2a657c5 commit 5ddb0d6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions __tests__/04_issue33_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { render, fireEvent, cleanup } from '@testing-library/react';

import { createGlobalState } from '../src/index';

describe('issue #33 spec', () => {
afterEach(cleanup);

it('should sync getGlobaState with useGlobalState', () => {
const initialState = {
count1: 0,
};
const { GlobalStateProvider, useGlobalState, getGlobalState } = createGlobalState(initialState);
const Counter = () => {
const [value, update] = useGlobalState('count1');
return (
<div>
<span>{value}</span>
<button type="button" onClick={() => update(value + 1)}>+1</button>
</div>
);
};
const App = () => (
<GlobalStateProvider>
<Counter />
</GlobalStateProvider>
);
const { getAllByText, container } = render(<App />);
expect(container.querySelector('span').textContent).toBe(String(getGlobalState('count1')));
fireEvent.click(getAllByText('+1')[0]);
expect(container.querySelector('span').textContent).toBe(String(getGlobalState('count1')));
});
});

0 comments on commit 5ddb0d6

Please sign in to comment.