forked from testing-library/dom-testing-library
-
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.
fix: mock brower event about testing-library#1327
- Loading branch information
1 parent
fdc12ec
commit e6346f7
Showing
4 changed files
with
100 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,53 @@ | ||
/** | ||
* @description before->cond->dispatch | ||
*/ | ||
|
||
export const beforeFn = ( | ||
initValue, | ||
event, | ||
before = config => { | ||
return config | ||
}, | ||
) => { | ||
let ConditionValue = initValue | ||
if (before && typeof before == 'function') { | ||
ConditionValue = before(ConditionValue) | ||
} | ||
if (!ConditionValue) { | ||
ConditionValue = { | ||
[`${event.type}`]: true, | ||
} | ||
} | ||
if (ConditionValue) { | ||
ConditionValue = { | ||
...ConditionValue, | ||
[`${event.type}`]: true, | ||
} | ||
} | ||
return ConditionValue | ||
} | ||
|
||
/** | ||
* @description judge attr exist about condition | ||
* @param {*} element | ||
* @param {*} AttrObj | ||
* @returns | ||
*/ | ||
export function valiateByAttr(element, AttrTrueObj, AttrFalseObj) { | ||
if (!element) { | ||
return false | ||
} | ||
let trueFlag = true | ||
for (const i in AttrTrueObj) { | ||
if (element[`${AttrTrueObj[i]}`]) { | ||
trueFlag = false | ||
} | ||
} | ||
let falseFlag = true | ||
for (const i in AttrFalseObj) { | ||
if (element[`${AttrFalseObj[i]}`]) { | ||
falseFlag = false | ||
} | ||
} | ||
return trueFlag && falseFlag | ||
} |