-
-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runtime error on Angular 13.1.0 #519
Comments
Bumping the @testing-library/dom dependency to 8.x should fix this. See testing-library/dom-testing-library#756 I quickly tried this and had to fix some typing errors in dom-selectors.ts. The export type MatcherFunction = (
content: string,
element: Element | null,
) => boolean
export type Matcher = MatcherFunction | RegExp | number | string This is how the export const byTextContent = (matcher: Matcher, options: MandatorySelectorMatchingOptions): DOMSelector => {
let textContentMatcher: Matcher;
const normalizer: NormalizerFn = options?.normalizer || getDefaultNormalizer(options);
const getTextContent = (elem: Element): string => normalizer(elem.textContent ?? '');
if (typeof matcher === 'string' || typeof matcher === 'number') {
textContentMatcher = (_, elem) => {
if (elem === null) {
return false;
}
if (options?.exact === false) {
return (
getTextContent(elem)
.toLowerCase()
.indexOf(matcher.toString().toLowerCase()) >= 0
);
}
return getTextContent(elem) === matcher;
};
} else if (matcher instanceof RegExp) {
textContentMatcher = (_, elem) => {
if (elem === null) {
return false;
}
return matcher.test(getTextContent(elem))
};
} else {
textContentMatcher = (_, elem) => {
if (elem === null) {
return false;
}
return matcher(getTextContent(elem), elem);
}
}
return new DOMSelector(el => DOMQueries.queryAllByText(el, textContentMatcher, options));
}; Then the tests pass with |
@molily do you want to create a PR? |
I'm seeing the same problem. I would say that this is a regression (it starts occurring after updating to ng 13 and spectator 9), but not a regression due to changes in this lib. As described in @testing-library #756, it's due to this line in
var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
const asymmetricMatcher =
typeof Symbol === 'function' && Symbol.for
? Symbol.for('jest.asymmetricMatcher')
: 0x1357a5;
const SPACE = ' '; pretty-format@26.6.2 is referenced by @testing-library/dom@7.26.5 which is referenced by @ngneat/spectator@9.0.0 I'm not sure whether this was an issue before ng 13 with spectator 9, since I updated everything together. I'll create a PR ASAP. |
API change while updating to new @testing-library/dom fixes: ngneat#519
fixes: ngneat#519 BREAKING CHANGE: This change will result in a compile error for any `MatcherFunction` that uses `HTMLElement` properties or functions. `MatcherFunction` in `@testing-library/dom` now receives a parameter of type `Element`, where it previously was `HTMLElement` - so users will have to test/cast to `HTMLElement` if they need `HTMLElement` properties or methods in their matcher function.
Thank you to everyone involved for the fast fix! |
Fixed in version 10.0.0 : https://github.com/ngneat/spectator/blob/master/CHANGELOG.md |
Is this a regression?
No
Description
I've just upgraded from Angular 13.0.3 to 13.1.0 and started receiving this error.
I've tried starting a new Angular project with
ng new
, get spectator installed and have@ngneat/spectator
imported in the spec file. The test runs without runtime error until I have it importedPlease provide a link to a minimal reproduction of the bug
https://github.com/ChaseOxide/spectator-crash
Please provide the exception or error you saw
Please provide the environment you discovered this bug in
Anything else?
Output from
npm ls pretty-format
:Do you want to create a pull request?
No
The text was updated successfully, but these errors were encountered: