forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support mocking native async methods (jestjs#3209)
* Support mocking native AsyncFunction * Add native-async-mock example test * Use strict * Return a promise from mock * Only test async * Revert returning promise
- Loading branch information
Showing
4 changed files
with
30 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015"] | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/async/native-async-mock/__tests__/native-async-mock-test.js
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,11 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
jest.mock('../native'); | ||
|
||
const native = require('../native'); | ||
|
||
test('mock works with native async', () => { | ||
expect(native.asyncMethod).toBeDefined(); | ||
}); |
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,14 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
function awaitable() { | ||
return Promise.resolve(); | ||
} | ||
|
||
module.exports.syncMethod = () => 42; | ||
|
||
module.exports.asyncMethod = async () => { | ||
await awaitable(); | ||
return 42; | ||
}; |
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