Skip to content

Commit

Permalink
[Refactor] Test: Create Setup File for Jest
Browse files Browse the repository at this point in the history
Configure Jest with Enzyme and export shallow function globally.

Signed-off-by: Progyan Bhattacharya <[email protected]>
  • Loading branch information
Progyan-APAC committed Oct 2, 2019
1 parent 367909f commit e85fca5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
7 changes: 7 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Adapter from 'enzyme-adapter-react-16';
import { shallow, configure } from 'enzyme';
import { SynchronousPromise } from 'synchronous-promise';

configure({ adapter: new Adapter() });

global.shallow = shallow;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@
},
"dependencies": {
"@babel/runtime": "^7.4.3"
},
"jest": {
"setupFilesAfterEnv": [ "<rootDir>/jest.setup.js" ]
}
}
6 changes: 1 addition & 5 deletions src/OptimisticToggle.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import React from 'react';
import Adapter from 'enzyme-adapter-react-16';
import { shallow, configure } from 'enzyme';
import { SynchronousPromise } from 'synchronous-promise';

import OptimisticToggle from './OptimisticToggle';

configure({ adapter: new Adapter() });


describe('Test <OptimisticToggle />', () => {
/**
* Ap: promiseA pending
Expand All @@ -18,6 +13,7 @@ describe('Test <OptimisticToggle />', () => {
* x: checked
*/
let wrapper, promise;

beforeEach(() => {
const action = () => {
// promise will be overwritten everytime we simulate click
Expand Down
6 changes: 1 addition & 5 deletions src/useOptimisticToggle.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import React from 'react';
import Adapter from 'enzyme-adapter-react-16';
import { shallow, configure } from 'enzyme';
import { SynchronousPromise } from 'synchronous-promise';

import useOptimisticToggle from './useOptimisticToggle';

configure({ adapter: new Adapter() });


describe('Test useOptimisticToggle()', () => {
/**
* Ap: promiseA pending
Expand All @@ -18,6 +13,7 @@ describe('Test useOptimisticToggle()', () => {
* x: checked
*/
let wrapper, promise;

beforeEach(() => {
const action = () => {
// promise will be overwritten everytime we simulate click
Expand Down

0 comments on commit e85fca5

Please sign in to comment.