Update react-dom, react-test-renderer to 16.8.0

This commit is contained in:
Jessica 2019-02-06 18:30:44 +09:00
parent 1f8e6dfd28
commit 58da7330ea
6 changed files with 56 additions and 5 deletions

View File

@ -1,10 +1,11 @@
// Type definitions for React (react-dom) 16.0
// Type definitions for React (react-dom) 16.8
// Project: http://facebook.github.io/react/
// Definitions by: Asana <https://asana.com>
// AssureSign <http://www.assuresign.com>
// Microsoft <https://microsoft.com>
// MartynasZilinskas <https://github.com/MartynasZilinskas>
// Josh Rutherford <https://github.com/theruther4d>
// Jessica Franco <https://github.com/Jessidhia>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8

View File

@ -178,4 +178,18 @@ describe('React dom test utils', () => {
shallowRenderer.getRenderOutput();
});
});
describe('act', () => {
it('accepts a sync callback that is void', () => {
ReactTestUtils.act(() => {});
});
it('rejects an async callback even if void', () => {
// $ExpectError
ReactTestUtils.act(async () => {});
});
it('rejects a callback that returns null', () => {
// $ExpectError
ReactTestUtils.act(() => null);
});
});
});

View File

@ -278,3 +278,17 @@ export function findRenderedComponentWithType<T extends Component<any>, C extend
* Call this in your tests to create a shallow renderer.
*/
export function createRenderer(): ShallowRenderer;
/**
* Wrap any code rendering and triggering updates to your components into `act()` calls.
*
* Ensures that the behavior in your tests matches what happens in the browser
* more closely by executing pending `useEffect`s before returning. This also
* reduces the amount of re-renders done.
*
* @param callback A synchronous, void callback that will execute as a single, complete React commit.
*
* @see https://reactjs.org/blog/2019/02/06/react-v16.8.0.html#testing-hooks
*/
// the "void | undefined" is here to forbid any sneaky "Promise" returns.
export function act(callback: () => void | undefined): void;

View File

@ -14,7 +14,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [

View File

@ -1,9 +1,10 @@
// Type definitions for react-test-renderer 16.0
// Type definitions for react-test-renderer 16.8
// Project: https://facebook.github.io/react/
// Definitions by: Arvitaly <https://github.com/arvitaly>
// Lochbrunner <https://github.com/lochbrunner>
// John Reilly <https://github.com/johnnyreilly>
// John Gozde <https://github.com/jgoz>
// Jessica Franco <https://github.com/Jessidhia>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@ -50,3 +51,17 @@ export interface TestRendererOptions {
createNodeMock(element: ReactElement<any>): any;
}
export function create(nextElement: ReactElement<any>, options?: TestRendererOptions): ReactTestRenderer;
/**
* Wrap any code rendering and triggering updates to your components into `act()` calls.
*
* Ensures that the behavior in your tests matches what happens in the browser
* more closely by executing pending `useEffect`s before returning. This also
* reduces the amount of re-renders done.
*
* @param callback A synchronous, void callback that will execute as a single, complete React commit.
*
* @see https://reactjs.org/blog/2019/02/06/react-v16.8.0.html#testing-hooks
*/
// the "void | undefined" is here to forbid any sneaky "Promise" returns.
export function act(callback: () => void | undefined): void;

View File

@ -1,5 +1,5 @@
import * as React from "react";
import { create, ReactTestInstance } from "react-test-renderer";
import React = require("react");
import { act, create, ReactTestInstance } from "react-test-renderer";
import { createRenderer } from 'react-test-renderer/shallow';
class TestComponent extends React.Component { }
@ -66,3 +66,10 @@ const shallowRenderer = createRenderer();
shallowRenderer.render(component);
shallowRenderer.getRenderOutput();
shallowRenderer.getMountedInstance();
// Only synchronous, void callbacks are acceptable for act()
act(() => {});
// $ExpectError
act(async () => {});
// $ExpectError
act(() => null);