Skip to content

Commit 7bc158d

Browse files
committed
Added tests.
1 parent e3c8ab1 commit 7bc158d

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# react-hooks-shared-state
22
[![npm version](https://badge.fury.io/js/react-hooks-shared-state.svg)](https://www.npmjs.com/package/react-hooks-shared-state)
3+
[![Coverage Status](https://coveralls.io/repos/github/kelp404/react-hooks-shared-state/badge.svg?branch=master)](https://coveralls.io/github/kelp404/react-hooks-shared-state?branch=master)
34
[![CircleCI](https://circleci.com/gh/kelp404/react-hooks-shared-state.svg?style=svg)](https://circleci.com/gh/kelp404/react-hooks-shared-state)
45

56
A global state for React with Hooks API.

__tests__/lib/__snapshots__/shared-state.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Object {
3232

3333
exports[`Call useState() with a path and a initial partial state to get the state. 1`] = `true`;
3434

35+
exports[`Call useState() with a path to get the state and the setter. 1`] = `true`;
36+
37+
exports[`Call useState() with a path to get the state and the setter. 2`] = `false`;
38+
3539
exports[`Setter assign a partial state and call setters with path. 1`] = `
3640
Object {
3741
"test": true,

__tests__/lib/shared-state.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ test('Call useState() with a initial state to get the state.', () => {
7777
expect(shareState.useState).toBeCalled();
7878
});
7979

80+
test('Call useState() with a path to get the state and the setter.', () => {
81+
const shareState = new SharedState();
82+
jest.spyOn(shareState, 'useState');
83+
shareState.setState({other: true});
84+
const component = () => {
85+
const [state, setState] = shareState.useState('test', true);
86+
expect(state).toMatchSnapshot();
87+
if (state) {
88+
setState(false);
89+
}
90+
91+
return React.createElement('div', null);
92+
};
93+
94+
renderer.create(React.createElement(component, null));
95+
expect(shareState.useState).toBeCalledTimes(2);
96+
});
97+
8098
test('Call useState() with a path and a initial partial state to get the state.', () => {
8199
const shareState = new SharedState();
82100
jest.spyOn(shareState, 'useState');

0 commit comments

Comments
 (0)