-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically wrap the relevant methods in
act
If @testing-library/react is already installed, we use their implementation of `act` - it's complete and provides useful warnings. If it's not installed, then we simply assume that the user is not testing a React application, and use a noop instead
- Loading branch information
Showing
5 changed files
with
88 additions
and
29 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
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,23 @@ | ||
/** | ||
* A simple compatibility method for react's "act". | ||
* If @testing-library/react is already installed, we just use | ||
* their implementation - it's complete and has useful warnings. | ||
* If @testing-library/react is *not* installed, then we just assume | ||
* that the user is not testing a react application, and use a noop instead. | ||
*/ | ||
|
||
type Callback = () => Promise<void | undefined> | void | undefined; | ||
type AsyncAct = (callback: Callback) => Promise<undefined>; | ||
type SyncAct = (callback: Callback) => void; | ||
|
||
let act: AsyncAct | SyncAct; | ||
|
||
try { | ||
act = require("@testing-library/react").act; | ||
} catch (_) { | ||
act = (callback: Function) => { | ||
callback(); | ||
}; | ||
} | ||
|
||
export default act; |
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