diff --git a/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js b/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js
index bacf9da7029a7..80dcaff819eef 100644
--- a/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js
+++ b/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js
@@ -1777,7 +1777,7 @@ describe('ReactHooksWithNoopRenderer', () => {
}, [props.count]);
return ;
}
- expect(() =>
+ expect(() => {
act(() => {
ReactNoop.render(, () =>
Scheduler.unstable_yieldValue('Sync effect'),
@@ -1787,8 +1787,8 @@ describe('ReactHooksWithNoopRenderer', () => {
'Sync effect',
]);
expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]);
- }),
- ).toErrorDev('flushSync was called from inside a lifecycle method');
+ });
+ }).toErrorDev('flushSync was called from inside a lifecycle method');
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
});
@@ -2648,32 +2648,32 @@ describe('ReactHooksWithNoopRenderer', () => {
}
const root1 = ReactNoop.createRoot();
- expect(() =>
+ expect(() => {
act(() => {
root1.render();
- }),
- ).toErrorDev([
+ });
+ }).toErrorDev([
'Warning: useEffect must not return anything besides a ' +
'function, which is used for clean-up. You returned: 17',
]);
const root2 = ReactNoop.createRoot();
- expect(() =>
+ expect(() => {
act(() => {
root2.render();
- }),
- ).toErrorDev([
+ });
+ }).toErrorDev([
'Warning: useEffect must not return anything besides a ' +
'function, which is used for clean-up. You returned null. If your ' +
'effect does not require clean up, return undefined (or nothing).',
]);
const root3 = ReactNoop.createRoot();
- expect(() =>
+ expect(() => {
act(() => {
root3.render();
- }),
- ).toErrorDev([
+ });
+ }).toErrorDev([
'Warning: useEffect must not return anything besides a ' +
'function, which is used for clean-up.\n\n' +
'It looks like you wrote useEffect(async () => ...) or returned a Promise.',
@@ -3052,32 +3052,32 @@ describe('ReactHooksWithNoopRenderer', () => {
}
const root1 = ReactNoop.createRoot();
- expect(() =>
+ expect(() => {
act(() => {
root1.render();
- }),
- ).toErrorDev([
+ });
+ }).toErrorDev([
'Warning: useInsertionEffect must not return anything besides a ' +
'function, which is used for clean-up. You returned: 17',
]);
const root2 = ReactNoop.createRoot();
- expect(() =>
+ expect(() => {
act(() => {
root2.render();
- }),
- ).toErrorDev([
+ });
+ }).toErrorDev([
'Warning: useInsertionEffect must not return anything besides a ' +
'function, which is used for clean-up. You returned null. If your ' +
'effect does not require clean up, return undefined (or nothing).',
]);
const root3 = ReactNoop.createRoot();
- expect(() =>
+ expect(() => {
act(() => {
root3.render();
- }),
- ).toErrorDev([
+ });
+ }).toErrorDev([
'Warning: useInsertionEffect must not return anything besides a ' +
'function, which is used for clean-up.\n\n' +
'It looks like you wrote useInsertionEffect(async () => ...) or returned a Promise.',
@@ -3104,11 +3104,11 @@ describe('ReactHooksWithNoopRenderer', () => {
}
const root = ReactNoop.createRoot();
- expect(() =>
+ expect(() => {
act(() => {
root.render();
- }),
- ).toErrorDev(['Warning: useInsertionEffect must not schedule updates.']);
+ });
+ }).toErrorDev(['Warning: useInsertionEffect must not schedule updates.']);
expect(() => {
act(() => {
@@ -3359,32 +3359,32 @@ describe('ReactHooksWithNoopRenderer', () => {
}
const root1 = ReactNoop.createRoot();
- expect(() =>
+ expect(() => {
act(() => {
root1.render();
- }),
- ).toErrorDev([
+ });
+ }).toErrorDev([
'Warning: useLayoutEffect must not return anything besides a ' +
'function, which is used for clean-up. You returned: 17',
]);
const root2 = ReactNoop.createRoot();
- expect(() =>
+ expect(() => {
act(() => {
root2.render();
- }),
- ).toErrorDev([
+ });
+ }).toErrorDev([
'Warning: useLayoutEffect must not return anything besides a ' +
'function, which is used for clean-up. You returned null. If your ' +
'effect does not require clean up, return undefined (or nothing).',
]);
const root3 = ReactNoop.createRoot();
- expect(() =>
+ expect(() => {
act(() => {
root3.render();
- }),
- ).toErrorDev([
+ });
+ }).toErrorDev([
'Warning: useLayoutEffect must not return anything besides a ' +
'function, which is used for clean-up.\n\n' +
'It looks like you wrote useLayoutEffect(async () => ...) or returned a Promise.',
diff --git a/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee b/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee
index 772905b7e0142..c9caacb9c405b 100644
--- a/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee
+++ b/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee
@@ -131,6 +131,7 @@ describe 'ReactCoffeeScriptClass', ->
expect(->
act ->
root.render React.createElement(Foo, foo: 'foo')
+ return
).toErrorDev 'Foo: getDerivedStateFromProps() is defined as an instance method and will be ignored. Instead, declare it as a static method.'
it 'warns if getDerivedStateFromError is not static', ->
@@ -142,6 +143,7 @@ describe 'ReactCoffeeScriptClass', ->
expect(->
act ->
root.render React.createElement(Foo, foo: 'foo')
+ return
).toErrorDev 'Foo: getDerivedStateFromError() is defined as an instance method and will be ignored. Instead, declare it as a static method.'
it 'warns if getSnapshotBeforeUpdate is static', ->
@@ -153,6 +155,7 @@ describe 'ReactCoffeeScriptClass', ->
expect(->
act ->
root.render React.createElement(Foo, foo: 'foo')
+ return
).toErrorDev 'Foo: getSnapshotBeforeUpdate() is defined as a static method and will be ignored. Instead, declare it as an instance method.'
it 'warns if state not initialized before static getDerivedStateFromProps', ->
@@ -169,6 +172,7 @@ describe 'ReactCoffeeScriptClass', ->
expect(->
act ->
root.render React.createElement(Foo, foo: 'foo')
+ return
).toErrorDev (
'`Foo` uses `getDerivedStateFromProps` but its initial state is ' +
'undefined. This is not recommended. Instead, define the initial state by ' +
diff --git a/packages/react/src/__tests__/ReactES6Class-test.js b/packages/react/src/__tests__/ReactES6Class-test.js
index 67b9e11a49805..5cee6f961948b 100644
--- a/packages/react/src/__tests__/ReactES6Class-test.js
+++ b/packages/react/src/__tests__/ReactES6Class-test.js
@@ -147,7 +147,9 @@ describe('ReactES6Class', () => {
return
;
}
}
- expect(() => act(() => root.render())).toErrorDev(
+ expect(() => {
+ act(() => root.render());
+ }).toErrorDev(
'Foo: getDerivedStateFromProps() is defined as an instance method ' +
'and will be ignored. Instead, declare it as a static method.',
);
@@ -162,7 +164,9 @@ describe('ReactES6Class', () => {
return ;
}
}
- expect(() => act(() => root.render())).toErrorDev(
+ expect(() => {
+ act(() => root.render());
+ }).toErrorDev(
'Foo: getDerivedStateFromError() is defined as an instance method ' +
'and will be ignored. Instead, declare it as a static method.',
);
@@ -175,7 +179,9 @@ describe('ReactES6Class', () => {
return ;
}
}
- expect(() => act(() => root.render())).toErrorDev(
+ expect(() => {
+ act(() => root.render());
+ }).toErrorDev(
'Foo: getSnapshotBeforeUpdate() is defined as a static method ' +
'and will be ignored. Instead, declare it as an instance method.',
);
@@ -193,7 +199,9 @@ describe('ReactES6Class', () => {
return ;
}
}
- expect(() => act(() => root.render())).toErrorDev(
+ expect(() => {
+ act(() => root.render());
+ }).toErrorDev(
'`Foo` uses `getDerivedStateFromProps` but its initial state is ' +
'undefined. This is not recommended. Instead, define the initial state by ' +
'assigning an object to `this.state` in the constructor of `Foo`. ' +