Skip to content

Commit 67caa64

Browse files
committed
react/redux testing library update
1 parent 9331184 commit 67caa64

File tree

10 files changed

+2545
-238
lines changed

10 files changed

+2545
-238
lines changed

__mocks__/fileMock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "test-file-stub";

__mocks__/styleMocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = 'test-file-stub';
1+
module.exports = {};

__tests__/composerTest.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import { createStore } from "redux";
3+
import { Provider } from "react-redux";
4+
import { render, screen, fireEvent } from "./test-utils.js";
5+
import HistoryContainer from "../src/client/components/containers/HistoryContainer";
6+
import "@testing-library/jest-dom/extend-expect";
7+
import store from "../src/client/store";
8+
import { ElectronHttpExecutor } from "electron-updater/out/electronHttpExecutor";
9+
10+
test("renders", () => {
11+
render(<HistoryContainer />);
12+
13+
screen.debug();
14+
});
15+
16+
/* FOR EACH COMPONENT - UNIT TESTING */
17+
//renders
18+
//buttons work (clear history, etc.)
19+
//forms function (accepts input)
20+
//state updates appropriately

__tests__/test-utils.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// test-utils.js
2+
import React from "react";
3+
import { render as rtlRender } from "@testing-library/react";
4+
import { createStore } from "redux";
5+
import { Provider } from "react-redux";
6+
import reducers from "../src/client/reducers/index.js";
7+
8+
const initialState = {
9+
currentTab: "First Tab",
10+
reqResArray: [],
11+
history: [],
12+
collections: [],
13+
warningMessage: "",
14+
newRequestFields: {
15+
protocol: "",
16+
url: "http://",
17+
method: "GET",
18+
graphQL: false,
19+
gRPC: false,
20+
},
21+
newRequestHeaders: {
22+
headersArr: [],
23+
count: 0,
24+
},
25+
newRequestStreams: {
26+
streamsArr: [],
27+
count: 0,
28+
streamContent: [],
29+
selectedPackage: null,
30+
selectedRequest: null,
31+
selectedService: null,
32+
selectedStreamingType: null,
33+
initialQuery: null,
34+
queryArr: null,
35+
protoPath: null,
36+
services: null,
37+
protoContent: "",
38+
},
39+
newRequestCookies: {
40+
cookiesArr: [],
41+
count: 0,
42+
},
43+
newRequestBody: {
44+
bodyContent: "",
45+
bodyVariables: "",
46+
bodyType: "raw",
47+
rawType: "Text (text/plain)",
48+
JSONFormatted: true,
49+
},
50+
newRequestSSE: {
51+
isSSE: false,
52+
},
53+
};
54+
55+
function render(
56+
ui,
57+
{
58+
initialState = initialState,
59+
store = createStore(reducers, initialState),
60+
...renderOptions
61+
} = {}
62+
) {
63+
function Wrapper({ children }) {
64+
return <Provider store={store}>{children}</Provider>;
65+
}
66+
return rtlRender(ui, { wrapper: Wrapper, ...renderOptions });
67+
}
68+
69+
// re-export everything
70+
export * from "@testing-library/react";
71+
72+
// override render method
73+
export { render };

jest.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { defaults } = require("jest-config");
2+
3+
module.exports = {
4+
moduleDirectories: ["node_modules"],
5+
verbose: true,
6+
runner: "@jest-runner/electron",
7+
testEnvironment: "@jest-runner/electron/environment",
8+
moduleNameMapper: {
9+
"\\.(css.|less|sass|scss)$": "<rootDir>/__mocks__/styleMocks.js",
10+
"\\.(gif|ttf|eot|svg|png)$": "<rootDir>/__mocks__/fileMock.js",
11+
},
12+
resolver: null,
13+
};

0 commit comments

Comments
 (0)