Skip to content

Commit ff70f44

Browse files
committed
Changed getSnapshot test to more closely mimic real usage
1 parent 16aa7fe commit ff70f44

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

test.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,36 @@ Object.entries(POLYFILLS).forEach(([name, polyfill]) => {
119119
constructor(props) {
120120
super(props);
121121
this.state = {count: 1};
122+
this.setRef = ref => {
123+
this.divRef = ref;
124+
};
122125
}
123126
static getDerivedStateFromProps(nextProps, prevState) {
124127
return {
125128
count: prevState.count + nextProps.incrementBy,
126129
};
127130
}
128131
getSnapshotBeforeUpdate(prevProps, prevState) {
129-
return prevState.count * 2 + this.state.count * 3;
132+
expect(prevProps).toEqual({incrementBy: 2});
133+
expect(prevState).toEqual({count: 3});
134+
return this.divRef.textContent;
130135
}
131136
componentDidUpdate(prevProps, prevState, snapshot) {
132137
expect(prevProps).toEqual({incrementBy: 2});
133138
expect(prevState).toEqual({count: 3});
134139
expect(this.props).toEqual({incrementBy: 3});
135140
expect(this.state).toEqual({count: 6});
136-
expect(snapshot).toBe(24);
141+
expect(snapshot).toBe('3');
137142
componentDidUpdateCalled = true;
138143
}
139144
render() {
140-
return React.createElement('div', null, this.state.count);
145+
return React.createElement(
146+
'div',
147+
{
148+
ref: this.setRef,
149+
},
150+
this.state.count
151+
);
141152
}
142153
}
143154

0 commit comments

Comments
 (0)