feat(curriculum): add spy helper (#42566)

* Added initial version of spy helper

* add missing backslashes

* update to check for line start

* change __fixtures file extensions to .ts from .tsx

* add to exports and add documentation

* add tests

* update event.preventDefault() test
This commit is contained in:
awu43
2021-07-16 00:20:03 -07:00
committed by GitHub
parent 3b32da0191
commit 4071b72a6c
7 changed files with 85 additions and 14 deletions

View File

@@ -101,19 +101,11 @@ Submitting the form should run `handleSubmit` which should set the `submit` prop
`handleSubmit` should call `event.preventDefault`
```js
const handleSubmit = MyForm.prototype.handleSubmit.toString();
const allMatches = handleSubmit.match(/\bevent\.preventDefault\(\s*?\)/g) ?? [];
const blockCommented = handleSubmit.match(
/\/\*.*?\bevent\.preventDefault\(\s*?\).*?\*\//gs
);
const lineCommented = handleSubmit.match(
/\/\/.*?\bevent\.preventDefault\(\s*?\)/g
);
const commentedMatches = [...(blockCommented ?? []), ...(lineCommented ?? [])];
assert(
// At least one event.preventDefault() call exists and is not commented out
allMatches.length > commentedMatches.length
__helpers.isCalledWithNoArgs(
'event.preventDefault',
MyForm.prototype.handleSubmit.toString()
)
);
```