fix(zone.js): zone.js patch jest should handle done correctly#36022
Closed
JiaLiPassion wants to merge 1 commit intoangular:masterfrom
Closed
fix(zone.js): zone.js patch jest should handle done correctly#36022JiaLiPassion wants to merge 1 commit intoangular:masterfrom
JiaLiPassion wants to merge 1 commit intoangular:masterfrom
Conversation
5525d99 to
031652a
Compare
mhevery
reviewed
Mar 30, 2020
mhevery
approved these changes
Mar 31, 2020
Contributor
kara
suggested changes
Apr 6, 2020
Contributor
kara
left a comment
There was a problem hiding this comment.
Small grammatical changes
Can we also update the commit message to change 'support' to 'supports':
zone.js support jest test.each() methods => zone.js supports jest test.each() methods
Contributor
Author
|
@kara , thanks for the review, I just updated the comment and the commit message. |
`zone.js` supports jest `test.each()` methods, but it
introduces a bug, which is the `done()` function will not be handled correctly.
```
it('should work with done', done => {
// done will be undefined.
});
```
The reason is the logic of monkey patching `test` method is different from `jasmine` patch
// jasmine patch
```
return testBody.length === 0
? () => testProxyZone.run(testBody, null)
: done => testProxyZone.run(testBody, null, [done]);
```
// jest patch
```
return function(...args) {
return testProxyZone.run(testBody, null, args);
};
```
the purpose of this change is to handle the following cases.
```
test.each([1, 2])('test.each', (arg1, arg2) => {
expect(arg1).toBe(1);
expect(arg2).toBe(2);
});
```
so in jest, it is a little complex, because the `testBody`'s parameter may be bigger than 1, so the
logic in `jasmine`
```
return testBody.length === 0
? () => testProxyZone.run(testBody, null)
: done => testProxyZone.run(testBody, null, [done]);
```
will not work for `test.each` in jest.
So in this PR, I created a dynamic `Function` to return the correct length of paramters (which is required by jest core), to handle
1. normal `test` with or without `done`.
2. each with parameters with or without done.
Contributor
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
zone.jssupport jesttest.each()methods, but itintroduces a bug, which is the
done()function will not be handled correctly.The reason is the logic of monkey patching
testmethod is different fromjasminepatch// jasmine patch
// jest patch
the purpose of this change is to handle the following cases.
so in jest, it is a little complex, because the
testBody's parameter may be bigger than 1, so thelogic in
jasminewill not work for
test.eachin jest.So in this PR, I created a dynamic
Functionto return the correct length of paramters (which is required by jest core), to handletestwith or withoutdone.PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: The issue is found at
jest-preset-angularrepo here, thymikee/jest-preset-angular#356