Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3316d06
commit 5fabd4b
Showing
16 changed files
with
788 additions
and
625 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const {getElementDisplayName} = require('../__tests__/helpers/utils') | ||
const actual = jest.requireActual('../utils') | ||
|
||
function getTrackedElementValues(element) { | ||
return { | ||
value: element.value, | ||
checked: element.checked, | ||
selectionStart: element.selectionStart, | ||
selectionEnd: element.selectionEnd, | ||
selectedOptions: element.selectedOptions | ||
? Array.from(element.selectedOptions).map(o => o.value) | ||
: null, | ||
} | ||
} | ||
|
||
function wrapWithTestData(fn) { | ||
return async (element, init) => { | ||
const before = getTrackedElementValues(element) | ||
const testData = { | ||
before, | ||
elementDisplayName: getElementDisplayName(element), | ||
} | ||
|
||
// put it on the element so the event handler can grab it | ||
element.testData = testData | ||
const result = await fn(element, init) | ||
|
||
const after = getTrackedElementValues(element) | ||
Object.assign(testData, {after}) | ||
|
||
// elete the testData for the next event | ||
delete element.testData | ||
return result | ||
} | ||
} | ||
|
||
const mockFireEvent = wrapWithTestData(actual.fireEvent) | ||
for (const key of Object.keys(actual.fireEvent)) { | ||
if (typeof actual.fireEvent[key] === 'function') { | ||
mockFireEvent[key] = wrapWithTestData(actual.fireEvent[key], key) | ||
} else { | ||
mockFireEvent[key] = actual.fireEvent[key] | ||
} | ||
} | ||
|
||
module.exports = { | ||
...actual, | ||
fireEvent: mockFireEvent, | ||
} |
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
Oops, something went wrong.