Component is not resolved ... Did you run and wait for 'resolveComponentResources()'?
See original GitHub issue๐ Bug Report
To Reproduce
- Install the default workspace with a single Angular application using
npx create-nx-workspace@latestcommand. - Updating packages:
"jest": "27.0.4",
"jest-preset-angular": "9.0.3",
"ts-jest": "27.0.3"
- Updating the root
jest.config.jsto:
require('jest-preset-angular/ngcc-jest-processor');
module.exports = {
projects: ['<rootDir>/apps/test'],
};
- Updating the application
jest.config.jsto:
module.exports = {
displayName: 'test',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$'
}
},
coverageDirectory: '../../coverage/apps/test',
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment'
]
};
Updating "postinstall": "node ./decorate-angular-cli.js && ngcc" and repeating npm i to generate UMD packages.
Steps to reproduce the behavior:
Run npm run test.
Result:
Component 'AppComponent' is not resolved:
- templateUrl: ./app.component.html
- styleUrls: ["./app.component.scss"]
Did you run and wait for 'resolveComponentResources()'?
Expected behavior
Correct test processing as with default setting and versions of:
"jest": "26.2.2",
"jest-preset-angular": "8.4.0",
"ts-jest": "26.5.5"
Error log:
nx run test:test
FAIL test apps/test/src/app/app.component.spec.ts
AppComponent
ร should create the app (10 ms)
ร should have as title 'test' (2 ms)
ร should render title (1 ms)
โ AppComponent โบ should create the app
Component 'AppComponent' is not resolved:
- templateUrl: ./app.component.html
- styleUrls: ["./app.component.scss"]
Did you run and wait for 'resolveComponentResources()'?
at Function.get (../../../packages/core/src/render3/jit/directive.ts:82:17)
at getComponentDef (../../../packages/core/src/render3/definition.ts:735:14)
at verifyDeclarationsHaveDefinitions (../../../packages/core/src/render3/jit/module.ts:242:17)
at Array.forEach (<anonymous>)
at verifySemanticsOfNgModuleDef (../../../packages/core/src/render3/jit/module.ts:212:16)
at Function.get (../../../packages/core/src/render3/jit/module.ts:167:13)
at R3TestBedCompiler.Object.<anonymous>.R3TestBedCompiler.applyProviderOverridesToModule (../../../packages/core/testing/src/r3_test_bed_compiler.ts:414:49)
at R3TestBedCompiler.Object.<anonymous>.R3TestBedCompiler.compileTestModule (../../../packages/core/testing/src/r3_test_bed_compiler.ts:677:10)
at R3TestBedCompiler.Object.<anonymous>.R3TestBedCompiler.finalize (../../../packages/core/testing/src/r3_test_bed_compiler.ts:245:10)
at TestBedRender3.get (../../../packages/core/testing/src/r3_test_bed.ts:370:43)
envinfo
System:
OS: Windows 10, NodeJS 14.17.0
Npm packages:
jest: 27.0.4
jest-preset-angular: 9.0.3
typescript: 4.2.4
Issue Analytics
- State:
- Created 2 years ago
- Comments:15
Top Results From Across the Web
testing angular components with jest gives ... - Stack Overflow
I'm trying to test Angular components with jest via jest-preset-angular. it can run the ... app.component.scss"] Did you run and wait for ......
Read more >Update Jest to 27.x version - Itilin
The second error โ Component is not resolved. This error, like the previous one, ... Did you run and wait for 'resolveComponentResources()'?
Read more >Upgraded to Angular 12, SSR not working, cannot resolve ...
app.component.css"] Did you run and wait for 'resolveComponentResources()'? The error is thrown after ssr-build and ssr-serve are completeย ...
Read more >Angular >=13 | jest-preset-angular - GitHub Pages
With Jest 28 and jest-preset-angular v12.0.0, ng-jest-resolver is no longer required to have in Jest config. This resolver is also excluded from our...
Read more >jest-preset-angular - Bountysource
[Bug]: Component not resolved error when testing conditional templateUrl $ 0 ... After upgrading angular version to 14,when running unit testcases(npm run ......
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
this is because Nrwl Nx needs to have migration for Jest config. In root
jest-preset.js,which refers to
node_modules/@nrwl/jest/preset/jest-preset.js, the config should beIf you want to use Jest 27, you need to override root
jest-preset.jswith the config above or wait for Nrwl Nx team to release a new version.@mlc-mlapis do you mind sharing exactly what it was that fixed your issue? I just upgraded out Nx workspace to 12.4.0 (which has the migration that @ahnpnl mentions, ie.
testEnvironment: 'jsdom'in the root) but I am getting the same error as you still. This is all the code isjest-preset-angular: 9.0.3jest: 27.0.3ts-jest: 27.0.3I tried to override test environment in the projects jest.config.js as well but no dice.