Skip to content

Commit fbd11d3

Browse files
committed
Cover the UNSAFE_* alias setter directly
Assigning `componentWillUpdate` on an instance was only ever exercised by `useReducer` installing its own; with that gone the setter half of the `UNSAFE_*` alias accessors has no caller in the suite. It is still a supported path for user code, so test it on its own.
1 parent d18a874 commit fbd11d3

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

compat/test/browser/component.test.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,28 @@ describe('components', () => {
192192
expect(spy).toHaveBeenCalledOnce();
193193
});
194194

195+
it('should support assigning componentWillUpdate on an instance', () => {
196+
let spy = vi.fn();
197+
198+
class Foo extends React.Component {
199+
constructor(props) {
200+
super(props);
201+
// The unprefixed methods are getter/setter aliases, so a plain
202+
// assignment has to be forwarded onto the instance itself.
203+
this.componentWillUpdate = spy;
204+
}
205+
206+
render() {
207+
return <h1>foo</h1>;
208+
}
209+
}
210+
211+
React.render(<Foo />, scratch);
212+
// Trigger an update
213+
React.render(<Foo />, scratch);
214+
expect(spy).toHaveBeenCalledOnce();
215+
});
216+
195217
it('should not forward refs on class components', () => {
196218
const ref = createRef();
197219
class Foo extends React.Component {

0 commit comments

Comments
 (0)