Skip to content
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

expect matchers are not extended with jest #562

Closed
grosch opened this issue Jun 22, 2022 · 9 comments
Closed

expect matchers are not extended with jest #562

grosch opened this issue Jun 22, 2022 · 9 comments

Comments

@grosch
Copy link

grosch commented Jun 22, 2022

Is this a regression?

Yes

Description

The custom matchers you've defined, like toHaveExactText, do not work with jest setups.

I'm 99% sure the issue is that there is no call to expect.extend as shown at https://jestjs.io/docs/expect#expectextendmatchers but I don't understand the setup enough to provide a PR for this fix.

Please provide a link to a minimal reproduction of the bug

Just try to use one with a jest config and it'll fail.

Please provide the exception or error you saw

TypeError: expect(...).toHaveExactText is not a function
    at /Users/scott/foo/lamp/src/app/button-enabled-dialog/button-enabled-dialog.component.spec.ts:62:28
    at l.invoke (/Users/scott/foo/lamp/node_modules/zone.js/fesm2015/zone-testing-bundle.min.js:13:6400)
    at ProxyZoneSpec.onInvoke (/Users/scott/foo/lamp/node_modules/zone.js/fesm2015/zone-testing-bundle.min.js:110:2047)
    at l.invoke (/Users/scott/foo/lamp/node_modules/zone.js/fesm2015/zone-testing-bundle.min.js:13:6340)
    at a.run (/Users/scott/foo/lamp/node_modules/zone.js/fesm2015/zone-testing-bundle.min.js:13:1812)
    at Object.o (/Users/scott/foo/lamp/node_modules/zone.js/fesm2015/zone-testing-bundle.min.js:134:592)
    at Promise.then.completed (/Users/scott/foo/lamp/node_modules/jest-circus/build/utils.js:333:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/Users/scott/foo/lamp/node_modules/jest-circus/build/utils.js:259:10)
    at _callCircusTest (/Users/scott/foo/lamp/node_modules/jest-circus/build/run.js:277:40)
    at _runTest (/Users/scott/foo/lamp/node_modules/jest-circus/build/run.js:209:3)
    at _runTestsForDescribeBlock (/Users/scott/foo/lamp/node_modules/jest-circus/build/run.js:97:9)
    at _runTestsForDescribeBlock (/Users/scott/foo/lamp/node_modules/jest-circus/build/run.js:91:9)
    at _runTestsForDescribeBlock (/Users/scott/foo/lamp/node_modules/jest-circus/build/run.js:91:9)
    at run (/Users/scott/foo/lamp/node_modules/jest-circus/build/run.js:31:3)
    at runAndTransformResultsToJestFormat (/Users/scott/foo/lamp/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:135:21)

Please provide the environment you discovered this bug in

Angular CLI: 14.0.0
Node: 18.4.0 (Unsupported)
Package Manager: yarn 1.22.19 
OS: darwin arm64

Angular: 14.0.0
... animations, cdk, cli, common, core, forms, language-service
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1400.0
@angular-devkit/build-angular   14.0.0
@angular-devkit/core            14.0.0
@angular-devkit/schematics      14.0.0
@angular/compiler               14.0.2
@angular/compiler-cli           14.0.2
@schematics/angular             14.0.0
ng-packagr                      14.0.0
rxjs                            6.6.3
typescript                      4.7.3

Anything else?

No response

Do you want to create a pull request?

No

@grosch
Copy link
Author

grosch commented Jun 22, 2022

I'm going to guess that it's a difference between using ESM modules or not?

@grosch
Copy link
Author

grosch commented Jun 22, 2022

example.zip

Attached is a bare minimum project that is setup to use jest with ESM modules and shows the issue if you just do a 'yarn test'

@grosch
Copy link
Author

grosch commented Jun 23, 2022

@NetanelBasal Were you able to reproduce with the zip I provided?

@NetanelBasal
Copy link
Member

Can you do it on stackblitz?

@grosch
Copy link
Author

grosch commented Jun 24, 2022

Maybe? Not sure how that's easier than just using the zip I gave you. I set it up at https://angular-ivy-rtojsi.stackblitz.io but I have no idea how to run jest on stackblitz so not sure if it'll fail the same way or not.

@NetanelBasal
Copy link
Member

The issue is that jest is undefined here.

@NetanelBasal
Copy link
Member

v11.1.0

@grosch
Copy link
Author

grosch commented Jun 26, 2022

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants