Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 30, 2022. It is now read-only.

Commit 167372c

Browse files
committed
fixed the tests
1 parent 628e293 commit 167372c

File tree

5 files changed

+127
-44
lines changed

5 files changed

+127
-44
lines changed

‎jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
moduleFileExtensions: ['ts', 'tsx', 'js'],
33
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|js?|tsx?|ts?)$',
4+
testPathIgnorePatterns: ['(/__tests__/common/.*)'],
45
globals: {
56
NODE_ENV: 'test',
67
},

‎src/__tests__/common/mountWithStore.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { ReactChild } from 'react';
2+
import { mount } from 'enzyme';
3+
import { Provider } from 'react-redux';
4+
import configureStore, {
5+
ModifiedConfigureStoreOptions,
6+
} from 'utils/redux/configureStore';
7+
8+
const mountWithStore = (children: ReactChild) => ({
9+
reducer = {},
10+
devTools = false,
11+
middleware,
12+
preloadedState,
13+
enhancers,
14+
}: ModifiedConfigureStoreOptions = {}) => {
15+
const store = configureStore({
16+
reducer,
17+
devTools,
18+
middleware,
19+
preloadedState,
20+
enhancers,
21+
});
22+
return mount(<Provider store={store}>{children}</Provider>);
23+
};
24+
25+
export default mountWithStore;

‎src/__tests__/pages/index.test.tsx

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,9 @@
11
/* eslint-disable react/jsx-props-no-spreading */
2-
import React, { ReactChild } from 'react';
3-
import { mount, ReactWrapper } from 'enzyme';
4-
import { Provider } from 'react-redux';
5-
import configureStore, {
6-
ModifiedConfigureStoreOptions,
7-
} from 'utils/redux/configureStore';
2+
import React from 'react';
3+
import { ReactWrapper } from 'enzyme';
84
import IndexPage from 'pages/index';
95
import { act } from 'react-dom/test-utils';
10-
11-
const mountWithStore = (children: ReactChild) => ({
12-
reducer = {},
13-
devTools = false,
14-
middleware,
15-
preloadedState,
16-
enhancers,
17-
}: ModifiedConfigureStoreOptions = {}) => {
18-
const store = configureStore({
19-
reducer,
20-
devTools,
21-
middleware,
22-
preloadedState,
23-
enhancers,
24-
});
25-
return mount(<Provider store={store}>{children}</Provider>);
26-
};
6+
import mountWithStore from '__tests__/common/mountWithStore';
277

288
describe('IndexPage', () => {
299
const testProp = {

‎src/__tests__/pages/index/[id].test.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import React from 'react';
2-
import { mount,ReactWrapper } from 'enzyme';
2+
import { ReactWrapper } from 'enzyme';
33
import { act } from 'react-dom/test-utils';
44
import Page, { getStaticProps } from 'pages/index/[id]';
5+
import mountWithStore from '__tests__/common/mountWithStore';
56

67
describe('Page', () => {
78
const testProp = {
89
test: 'test',
910
};
11+
1012
let TestPageWrapper: ReactWrapper;
11-
beforeAll(() => {
12-
act(() => {
13+
14+
beforeAll(async () => {
15+
await act(async () => {
1316
/* eslint-disable-next-line react/jsx-props-no-spreading */
14-
TestPageWrapper = mount(<Page id="testId" {...testProp} />);
17+
TestPageWrapper = mountWithStore(<Page id="testId" {...testProp} />)();
1518
});
16-
TestPageWrapper.update();
19+
// TestPageWrapper.update();
1720
});
1821

1922
it('should render without throwing an error', () => {
@@ -32,7 +35,7 @@ describe('Page', () => {
3235

3336
it('should render page process env correctly', () => {
3437
expect(TestPageWrapper.find('p').at(2).text()).toContain(
35-
process.env.TEST_PAGE_VAR
38+
process.env.NEXT_PUBLIC_TEST_PAGE_VAR
3639
);
3740
});
3841
});
Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,94 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Page should render without throwing an error 1`] = `
4-
<IndexPage
5-
id="testId"
6-
test="test"
4+
<Provider
5+
store={
6+
Object {
7+
"addReducer": [Function],
8+
"dispatch": [Function],
9+
"getState": [Function],
10+
"injectReducers": [Function],
11+
"reducer": Object {
12+
"text": [Function],
13+
},
14+
"removeReducers": [Function],
15+
"replaceReducer": [Function],
16+
"subscribe": [Function],
17+
"substituteReducers": [Function],
18+
Symbol(observable): [Function],
19+
}
20+
}
721
>
8-
<div>
9-
<p>
10-
Param: testId
11-
</p>
12-
<p>
13-
Props from _app.tsx: {"test":"test"}
14-
</p>
15-
<p>
16-
Page Process Env: TEST_TEST_PAGE_PROP
17-
</p>
18-
</div>
19-
</IndexPage>
22+
<IndexPage
23+
id="testId"
24+
test="test"
25+
>
26+
<main>
27+
<ManifestHead
28+
hrefCanonical="/index/testId"
29+
title="github_pwa dynamic-path"
30+
>
31+
<Head>
32+
<Component
33+
handleStateChange={null}
34+
inAmpMode={false}
35+
reduceComponentsToState={[Function]}
36+
/>
37+
</Head>
38+
</ManifestHead>
39+
<p>
40+
Param: testId
41+
</p>
42+
<p>
43+
Props from _app.tsx: {"test":"test"}
44+
</p>
45+
<p>
46+
Page Process Env: TEST_TEST_PAGE_PROP
47+
</p>
48+
<TextDivWrap>
49+
<DynamicStoreWrap
50+
callbackOnMount={[Function]}
51+
callbackOnUnmount={[Function]}
52+
>
53+
<DynamicStore
54+
callbackOnMount={[Function]}
55+
callbackOnUnmount={[Function]}
56+
store={
57+
Object {
58+
"addReducer": [Function],
59+
"dispatch": [Function],
60+
"getState": [Function],
61+
"injectReducers": [Function],
62+
"reducer": Object {
63+
"text": [Function],
64+
},
65+
"removeReducers": [Function],
66+
"replaceReducer": [Function],
67+
"subscribe": [Function],
68+
"substituteReducers": [Function],
69+
Symbol(observable): [Function],
70+
}
71+
}
72+
/>
73+
</DynamicStoreWrap>
74+
</TextDivWrap>
75+
<PrefixedLink
76+
href="/"
77+
>
78+
<Link
79+
as="/"
80+
href="/"
81+
>
82+
<a
83+
href="/"
84+
onClick={[Function]}
85+
onMouseEnter={[Function]}
86+
>
87+
index
88+
</a>
89+
</Link>
90+
</PrefixedLink>
91+
</main>
92+
</IndexPage>
93+
</Provider>
2094
`;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /