-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update documentation on automocking (#5630)
- Loading branch information
Showing
9 changed files
with
187 additions
and
4 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,3 @@ | ||
{ | ||
"presets": ["env"] | ||
} |
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,16 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
import utils from '../utils'; | ||
|
||
test('if utils are mocked', () => { | ||
expect(utils.authorize.mock).toBeTruthy(); | ||
expect(utils.isAuthorized.mock).toBeTruthy(); | ||
}); | ||
|
||
test('mocked implementation', () => { | ||
utils.authorize.mockReturnValue('mocked_token'); | ||
utils.isAuthorized.mockReturnValue(true); | ||
|
||
expect(utils.authorize()).toBe('mocked_token'); | ||
expect(utils.isAuthorized('not_wizard')).toBeTruthy(); | ||
}); |
9 changes: 9 additions & 0 deletions
9
examples/automatic_mocks/__tests__/disableAutomocking.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,9 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
import utils from '../utils'; | ||
|
||
jest.disableAutomock(); | ||
|
||
test('original implementation', () => { | ||
expect(utils.authorize()).toBe('token'); | ||
}); |
16 changes: 16 additions & 0 deletions
16
examples/automatic_mocks/__tests__/genMockFromModule.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,16 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
import utils from '../utils'; | ||
|
||
test('implementation created by automock', () => { | ||
expect(utils.authorize('wizzard')).toBeUndefined(); | ||
expect(utils.isAuthorized()).toBeUndefined(); | ||
}); | ||
|
||
test('implementation created by jest.genMockFromModule', () => { | ||
const utils = jest.genMockFromModule('../utils').default; | ||
utils.isAuthorized = jest.fn(secret => secret === 'not wizard'); | ||
|
||
expect(utils.authorize.mock).toBeTruthy(); | ||
expect(utils.isAuthorized('not wizard')).toEqual(true); | ||
}); |
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,12 @@ | ||
{ | ||
"devDependencies": { | ||
"babel-preset-env": "*", | ||
"jest": "*" | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"jest": { | ||
"automock": true | ||
} | ||
} |
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,8 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
export default { | ||
authorize: () => { | ||
return 'token'; | ||
}, | ||
isAuthorized: secret => secret === 'wizard', | ||
}; |