Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed potential error when hook suspends and current result is a…
…ccessed BREAKING CHANGE: Adjust types so that react renderer exports don't required extra generic parameter
- Loading branch information
Showing
14 changed files
with
110 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
import { ReactHooksRenderer } from '../types/react' | ||
|
||
describe('default renderer', () => { | ||
beforeEach(() => { | ||
jest.resetModules() | ||
}) | ||
|
||
test('should resolve native renderer as default renderer', () => { | ||
const expectedRenderer = require('../native/pure') as ReactHooksRenderer | ||
const actualRenderer = require('..') as ReactHooksRenderer | ||
|
||
expect(actualRenderer).toEqual(expectedRenderer) | ||
}) | ||
|
||
test('should resolve dom renderer as default renderer', () => { | ||
jest.doMock('react-test-renderer', () => { | ||
throw new Error('missing dependency') | ||
}) | ||
|
||
const expectedRenderer = require('../dom/pure') as ReactHooksRenderer | ||
const actualRenderer = require('..') as ReactHooksRenderer | ||
|
||
expect(actualRenderer).toEqual(expectedRenderer) | ||
}) | ||
|
||
test('should throw error if a default renderer cannot be resolved', () => { | ||
jest.doMock('react-test-renderer', () => { | ||
throw new Error('missing dependency') | ||
}) | ||
|
||
jest.doMock('react-dom', () => { | ||
throw new Error('missing dependency') | ||
}) | ||
|
||
const expectedMessage = | ||
"Could not auto-detect a React renderer. Are you sure you've installed one of the following\n - react-dom\n - react-test-renderer" | ||
|
||
expect(() => require('..')).toThrowError(new Error(expectedMessage)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,31 @@ | ||
import { ComponentType } from 'react' | ||
|
||
import { RenderHookOptions, RenderHookResult, Act } from '.' | ||
import { | ||
RenderHookOptions as BaseRenderHookOptions, | ||
RenderHookResult, | ||
Act, | ||
CleanupCallback | ||
} from '.' | ||
|
||
export type WrapperComponent<TProps> = ComponentType<TProps> | ||
|
||
export type RendererOptions<TProps> = { | ||
wrapper?: WrapperComponent<TProps> | ||
} | ||
|
||
export type RenderHookOptions<TProps> = BaseRenderHookOptions<TProps> & { | ||
wrapper?: WrapperComponent<TProps> | ||
} | ||
|
||
export type ReactHooksRenderer = { | ||
renderHook: <TProps, TResult>( | ||
callback: (props: TProps) => TResult, | ||
options?: RenderHookOptions<TProps, RendererOptions<TProps>> | ||
options?: RenderHookOptions<TProps> | ||
) => RenderHookResult<TProps, TResult> | ||
act: Act | ||
cleanup: () => void | ||
addCleanup: (callback: () => Promise<void> | void) => () => void | ||
removeCleanup: (callback: () => Promise<void> | void) => void | ||
addCleanup: (callback: CleanupCallback) => () => void | ||
removeCleanup: (callback: CleanupCallback) => void | ||
} | ||
|
||
export * from '.' |
This comment has been minimized.
Sorry, something went wrong.
ntuckerJan 24, 2021
ContributorThis comment has been minimized.
Sorry, something went wrong.
ntuckerJan 24, 2021
Contributor