-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Adding ngx-cookie-service broke Jest tests #39
Comments
I've tried following jest config without luck:
with babel packages installed (npm i -D babel-jest babel-preset-env) |
checking in to report the same issue. |
Same here. Not found a fix yet. |
Others do not pass because of stevermeister/ngx-cookie-service#39
The problem is that ngx-cookie-service is compiled to es2015, which must be transformed before tests.
then in your package json where the jest config is:
and create a .babelrc file in the project root with
|
Actually, the bigger issue is that |
The issue is related to Jest not transforming the files in node_modules folder. |
There is still an issue remaining because of stevermeister/ngx-cookie-service#39
There is still an issue remaining because of stevermeister/ngx-cookie-service#39
I combine these solutions to get my testing somewhat working: #39 (comment) and just-jeb/angular-builders#85 (comment) I have a nrwl/nx mono repo. I have been using jest to test everything on one-go. All the tests pass with no issues. I try to convert one app from karma to jest so that I can do this with jest:
I get this error:
With the combined solution, when I have my transform like this:
Running tests for the whole mono repo works, but the individual app will fail. When I have it like:
The individual app tests will pass, but the mono repo tests will fail |
Hi All, I just found a solution to this problem.
|
I've tried this but still getting the errors. I'm still getting
I've switched to ngx-cookie instead, which uses an additional dependency which isn't ideal but at least the tests work. |
Upgrading ngx-cookie-service to ^2.1.0 fixed the problem for me. If you can try updating ngx-cookie-service EDIT: Also, you need to have the __mocks__ file as mentioned by @KiranMantha. I did not need to add it to all my tests as indicated in step 3 as jest will do that automatically when it finds in import in the mocks folder |
Still running into this issue under |
Yes, still encountering issue, and followed the instructions to implement babel.. no joy... |
Why this issue is closed ? I updated from 2.1.0 to 2.2.0 and the error disappear. |
Was looking for something different - but as i ran into the 'same' problem with jest and another library - related to jest not transforming esm modules - i will leave this link here to save someone the headacke https://stackoverflow.com/questions/70571424/angular-v13-jest-with-nx-test-syntaxerror-cannot-use-import-statement-outside/70615775#70615775 |
Expected Behavior
Dependency should import correctly and operate normally during test runs
Actual Behavior
ttucker:rac-web-admin thomastucker$ yarn test
yarn run v1.9.2
$ jest
PASS src/app/auth/reducers/auth.reducer.spec.ts
AuthReducer
undefined action
✓ should return the default state (9ms)
LOGIN_SUCCESS
✓ should add a user set loggedIn to true in auth state (1ms)
LOGOUT
✓ should logout a user (1ms)
PASS src/app/+promotions/containers/add-promotion-page/add-promotion-page.component.spec.ts
AddPromotionPageComponent
✓ should create (120ms)
PASS src/app/core/containers/page-not-found/page-not-found.component.spec.ts
PageNotFoundComponent
✓ should create (116ms)
PASS src/app/core/containers/app/app.component.spec.ts
AppComponent
✓ should create (120ms)
PASS src/app/core/components/header/header.component.spec.ts
HeaderComponent
✓ should create (185ms)
PASS src/app/core/components/sidenav/sidenav.component.spec.ts
SidenavComponent
✓ should create (234ms)
FAIL src/app/app-routing.module.spec.ts
● Test suite failed to run
FAIL src/app/auth/services/auth-guard.service.spec.ts
● Test suite failed to run
FAIL src/app/auth/effects/auth.effects.spec.ts
● Test suite failed to run
FAIL src/app/+promotions/promotions.module.spec.ts
● Test suite failed to run
PASS src/app/auth/containers/login-page/login-page.component.spec.ts
Login Page
✓ should compile (390ms)
Test Suites: 4 failed, 7 passed, 11 total
Tests: 9 passed, 9 total
Snapshots: 4 passed, 4 total
Time: 3.301s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Steps to Reproduce the Problem
ng create app
add jest https://brianflove.com/2018/05/26/angular-jest-testing/
add ngx-cookie-service
view tests failing
Specifications
Version:
node - v9.4.0
npm - 5.6.0
Browser: ...
...
The text was updated successfully, but these errors were encountered: