-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update documentation on automocking #5630
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
954bc79
Update documentation about automocking
czystyl 9718940
Add tests for genMockFromModule
czystyl 186f559
Add test for enableAutomock
czystyl 42c02dc
Update genMockFromModule section
czystyl c02db18
Split examples
czystyl a9026ca
Update tests in examples
czystyl f9b2442
Request changes
czystyl e81f1b3
Remove automock guidance
thymikee def143e
Remove unnecessary comments
czystyl ddbc781
Merge remote-tracking branch 'origin/automocking-dock' into automocki…
czystyl 904f449
Update changelog
czystyl 91ea3b1
Add chore section to changelog
czystyl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add this under
### Chore & Maintenance
section belowFixes