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

Commit0225999

Browse files
committed
New test 'should not render the wrapped component when mapState does not produce change'
1 parent8f5f825 commit0225999

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

‎test/components/connect.spec.js‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,5 +1147,38 @@ describe('React', () => {
11471147
wrapper.setState({value:1});
11481148
expect(target.props.statefulValue).toEqual(1);
11491149
});
1150+
1151+
it('should not render the wrapped component when mapState does not produce change',()=>{
1152+
conststore=createStore(stringBuilder);
1153+
letrenderCalls=0;
1154+
letmapStateCalls=0;
1155+
1156+
@connect(()=>{
1157+
mapStateCalls++;
1158+
return{};// no change!
1159+
})
1160+
classContainerextendsComponent{
1161+
render(){
1162+
renderCalls++;
1163+
return<Passthrough{...this.props}/>;
1164+
}
1165+
}
1166+
1167+
TestUtils.renderIntoDocument(
1168+
<ProviderMockstore={store}>
1169+
<Container/>
1170+
</ProviderMock>
1171+
);
1172+
1173+
expect(renderCalls).toBe(1);
1174+
expect(mapStateCalls).toBe(1);
1175+
1176+
store.dispatch({type:'APPEND',body:'a'});
1177+
1178+
// After store a change mapState has been called
1179+
expect(mapStateCalls).toBe(2);
1180+
// But render is not because it did not make any actual changes
1181+
expect(renderCalls).toBe(1);
1182+
});
11501183
});
11511184
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp