-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 constructable checking should not be cached if the function prototy…
…pe function was added after first running (#1381)
- Loading branch information
Showing
4 changed files
with
81 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @author Kuitos | ||
* @since 2021-04-12 | ||
*/ | ||
|
||
import { getTargetValue } from '../common'; | ||
|
||
describe('getTargetValue', () => { | ||
it('should work well', () => { | ||
const a1 = getTargetValue(window, undefined); | ||
expect(a1).toEqual(undefined); | ||
|
||
const a2 = getTargetValue(window, null); | ||
expect(a2).toEqual(null); | ||
|
||
const a3 = getTargetValue(window, function bindThis(this: any) { | ||
return this; | ||
}); | ||
const a3returns = a3(); | ||
expect(a3returns).toEqual(window); | ||
}); | ||
|
||
it('should work well while function added prototype methods after first running', () => { | ||
function prototypeAddedAfterFirstInvocation(this: any, field: string) { | ||
this.field = field; | ||
} | ||
const notConstructableFunction = getTargetValue(window, prototypeAddedAfterFirstInvocation); | ||
// `this` of not constructable function will be bound automatically, and it can not be changed by calling with special `this` | ||
const result = {}; | ||
notConstructableFunction.call(result, '123'); | ||
expect(result).toStrictEqual({}); | ||
expect(window.field).toEqual('123'); | ||
|
||
prototypeAddedAfterFirstInvocation.prototype.addedFn = () => {}; | ||
const constructableFunction = getTargetValue(window, prototypeAddedAfterFirstInvocation); | ||
// `this` coule be available if it be predicated as a constructable function | ||
const result2 = {}; | ||
constructableFunction.call(result2, '456'); | ||
expect(result2).toStrictEqual({ field: '456' }); | ||
// window.field not be affected | ||
expect(window.field).toEqual('123'); | ||
}); | ||
}); |
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
1f97acf
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.
Deploy preview for qiankun ready!
✅ Preview
https://qiankun-njhad3ny0-umijs.vercel.app
Built with commit 1f97acf.
This pull request is being automatically deployed with vercel-action