Skip to content

Commit 0dfaff3

Browse files
authored
fix: tests updated
1 parent 6c4f502 commit 0dfaff3

File tree

6 files changed

+5300
-3
lines changed

6 files changed

+5300
-3
lines changed

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', {targets: {node: 'current'}}],
4+
'@babel/preset-typescript',
5+
],
6+
};

index.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import useContextDevTools from './index';
2+
3+
const devInit = jest.fn();
4+
const devSend = jest.fn();
5+
const devDisconnect = jest.fn();
6+
7+
const devToolsMock = {
8+
connect: jest.fn(() => ({
9+
init: devInit,
10+
send: devSend,
11+
disconnect: devDisconnect,
12+
})),
13+
};
14+
15+
describe('Dev Tools Extension', () => {
16+
(window as any).__REDUX_DEVTOOLS_EXTENSION__ = devToolsMock;
17+
const dispatchFn = jest.fn();
18+
const dispatchContext = useContextDevTools(dispatchFn);
19+
20+
test('Should initialize devTools', () => {
21+
dispatchContext.sendDispatch({});
22+
expect(dispatchFn).toHaveBeenCalledWith({});
23+
});
24+
25+
test('Should be able to send updated state', () => {
26+
dispatchContext.sendUpdatedState({});
27+
expect(devInit).toHaveBeenCalled();
28+
dispatchContext.sendUpdatedState({});
29+
expect(devSend).toHaveBeenCalled();
30+
});
31+
32+
test('Should be able to disconnect', () => {
33+
dispatchContext.disconnectDevTools();
34+
expect(devDisconnect).toHaveBeenCalled();
35+
});
36+
})
37+

index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let isInitialized = false;
44
let firstRender = false;
55
let oldArgs = {};
66

7-
export const useContextDevTools = (dispatch: Function) => {
7+
const useContextDevTools = (dispatch: Function) => {
88
if (!isInitialized) {
99
devTools.current = (window as any).__REDUX_DEVTOOLS_EXTENSION__.connect();
1010
isInitialized = true;
@@ -36,3 +36,5 @@ export const useContextDevTools = (dispatch: Function) => {
3636
disconnectDevTools,
3737
};
3838
};
39+
40+
export default useContextDevTools;

0 commit comments

Comments
 (0)