Movatterモバイル変換


[0]ホーム

URL:


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

Commite51a5f5

Browse files
committed
fixed tests
1 parent55f6581 commite51a5f5

File tree

5 files changed

+126
-44
lines changed

5 files changed

+126
-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
},
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
importReact,{ReactChild}from'react';
2+
import{mount}from'enzyme';
3+
import{Provider}from'react-redux';
4+
importconfigureStore,{
5+
ModifiedConfigureStoreOptions,
6+
}from'utils/redux/configureStore';
7+
8+
constmountWithStore=(children:ReactChild)=>({
9+
reducer={},
10+
devTools=false,
11+
middleware,
12+
preloadedState,
13+
enhancers,
14+
}:ModifiedConfigureStoreOptions={})=>{
15+
conststore=configureStore({
16+
reducer,
17+
devTools,
18+
middleware,
19+
preloadedState,
20+
enhancers,
21+
});
22+
returnmount(<Providerstore={store}>{children}</Provider>);
23+
};
24+
25+
exportdefaultmountWithStore;

‎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-
importReact,{ReactChild}from'react';
3-
import{mount,ReactWrapper}from'enzyme';
4-
import{Provider}from'react-redux';
5-
importconfigureStore,{
6-
ModifiedConfigureStoreOptions,
7-
}from'utils/redux/configureStore';
2+
importReactfrom'react';
3+
import{ReactWrapper}from'enzyme';
84
importIndexPagefrom'pages/index';
95
import{act}from'react-dom/test-utils';
10-
11-
constmountWithStore=(children:ReactChild)=>({
12-
reducer={},
13-
devTools=false,
14-
middleware,
15-
preloadedState,
16-
enhancers,
17-
}:ModifiedConfigureStoreOptions={})=>{
18-
conststore=configureStore({
19-
reducer,
20-
devTools,
21-
middleware,
22-
preloadedState,
23-
enhancers,
24-
});
25-
returnmount(<Providerstore={store}>{children}</Provider>);
26-
};
6+
importmountWithStorefrom'__tests__/common/mountWithStore';
277

288
describe('IndexPage',()=>{
299
consttestProp={

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

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

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

1921
it('should render without throwing an error',()=>{
@@ -32,7 +34,7 @@ describe('Page', () => {
3234

3335
it('should render page process env correctly',()=>{
3436
expect(TestPageWrapper.find('p').at(2).text()).toContain(
35-
process.env.TEST_PAGE_VAR
37+
process.env.NEXT_PUBLIC_TEST_PAGE_VAR
3638
);
3739
});
3840
});
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)

[8]ページ先頭

©2009-2025 Movatter.jp