Skip to content

Commit 24c80f3

Browse files
committed
Added tests.
1 parent e7a0bbc commit 24c80f3

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

.circleci/config.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: 2.0
2+
workflows:
3+
version: 2
4+
build:
5+
jobs:
6+
- node10
7+
- node12
8+
jobs:
9+
node10:
10+
working_directory: ~/react-hooks-shared-state
11+
docker:
12+
- image: node:10.15.3
13+
steps:
14+
- checkout
15+
- run: npm install
16+
- run: npm test
17+
18+
node12:
19+
working_directory: ~/react-hooks-shared-state
20+
docker:
21+
- image: node:12.1.0
22+
steps:
23+
- checkout
24+
- run: npm install
25+
- run: npm test
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`setState() is assign state and call setters. 1`] = `
4+
Object {
5+
"test": true,
6+
}
7+
`;

__tests__/lib/shared-state.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const SharedState = require('../../lib/shared-state');
2+
3+
test('setState() is assign state and call setters.', () => {
4+
const shareState = new SharedState();
5+
shareState.setters = [
6+
{
7+
path: 'test',
8+
set: jest.fn()
9+
},
10+
{
11+
set: jest.fn()
12+
}
13+
];
14+
shareState.setState({test: true});
15+
expect(shareState.state).toMatchSnapshot();
16+
expect(shareState.setters[0].set).toBeCalledWith(true);
17+
expect(shareState.setters[1].set).toBeCalledWith({test: true});
18+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"start": "./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
88
"build": "./node_modules/webpack/bin/webpack.js --env.mode=production",
9-
"test": "echo \"Error: no test specified\" && exit 1",
9+
"test": "./node_modules/jest/bin/jest.js --coverage",
1010
"ncu": "./node_modules/npm-check-updates/bin/ncu"
1111
},
1212
"repository": {

0 commit comments

Comments
 (0)