[Bug]: [ng13] - Cannot find module '@angular/common/locales/xxx'
See original GitHub issueVersion
11.0.0-rc2
Steps to reproduce
- Clone my repo at https://github.com/shajz/ng13-jest-locale-import-bug
npm cinpm test
Expected behavior
I expect locales to be registered correctly from test files
Actual behavior
$ npm test
> ng13-jest-locale-import-bug@0.0.0 test
> node --expose-gc ./node_modules/jest/bin/jest.js --no-cache --logHeapUsage
FAIL src/app/app.component.spec.ts
● Test suite failed to run
Cannot find module '@angular/common/locales/fr' from 'src/app/app.component.spec.ts'
1 | import { registerLocaleData } from '@angular/common';
> 2 | import localeFr from '@angular/common/locales/fr';
| ^
3 | import { TestBed } from '@angular/core/testing';
4 | import { AppComponent } from './app.component';
5 | registerLocaleData(localeFr);
at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
at Object.<anonymous> (src/app/app.component.spec.ts:2:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 5.473 s
Ran all test suites.
Additional context
Upgraded to Angular 13, followed instructions for jest-preset-angular@11 (using specified resolver, transformIgnorePatterns, transform; was using preset: jest-preset-angular before)
Environment
System:
OS: Windows 10 10.0.19043
CPU: (12) x64 Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
Binaries:
Node: 14.18.0 - ~\AppData\Local\Volta\tools\image\node\14.18.0\node.EXE
Yarn: 1.22.15 - C:\Program Files\Volta\yarn.EXE
npm: 7.20.6 - ~\AppData\Local\Volta\tools\image\npm\7.20.6\bin\npm.CMD
npmPackages:
jest: ^27.3.1 => 27.3.1
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:12 (1 by maintainers)
Top Results From Across the Web
cannot find module '@angular/core/testing' from ... - You.com
Steps to Reproduce ; [Bug]: [ng13] - Cannot find module '@angular/common/locales/xxx ... Github.com ; cannot find module '@angular/core/testing' from ' ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I manage to make it work by adding this in jest config file:
you can find an example in this repo https://github.com/cedricduffournet/test-ngrx-error
I did take a look at this and it appears that the problem is that
moduleFileExtensionsdoesn’t includemjs. This means that this extensions needs to be added manually.@ahnpnl, this should be added in the preset https://github.com/thymikee/jest-preset-angular/blob/1e7dbf8432d2c25a9a3d1e650db2abc3fa6a0466/presets/index.js#L12
@shajz, since you are not using the preset recommended settings via
preset: 'jest-preset-angular, you will need to addmoduleFileExtensionsin your jest config.