"jest-preset-angular" is a collection of default settings, Jest Serializers and AST Transformers to make Angular (v2+) compatible to be tested by Jest.
Questions tagged [jest-preset-angular]
41 questions
2
votes
1 answer
Adal.service.ts doesn't work for me in angular when I run the tests with Jest
Helpme please.
I'm migrating to Jest to run Unit Tests of ANGULAR, but when executing I get an error:
FAIL
src/app/modules/dashboard/components/navbar/navbar.component.spec.ts
Test suite failed to run
ReferenceError: AuthenticationContext is not…

mpuertao
- 21
- 4
2
votes
3 answers
How to resolve the error "ERR! code ELIFECYCLE"?
I am using the Jest to perform the unit testing.
"jest": "^26.4.2",
"jest-preset-angular": "^8.3.1"
All the test has been passed and ran but got an error as below
Test Suites: 20 passed, 20 total
Tests: 26 passed, 26 total
Snapshots: 2…

San Jaisy
- 15,327
- 34
- 171
- 290
2
votes
1 answer
Jest and Serialize-ts Count find type for field:
I am facing an issue while running testing using jest in my angular application after upgrading jest to v9 while using serilize-ts
The error is:
Count find type for field: amount
4 | export class Price {
5 | @Field()
> 6 | …

Nour
- 5,609
- 3
- 21
- 24
2
votes
1 answer
Is it possible to activate coverage in jest but not printed it in console?
Coming from Karma I like to keep a browser tab opened to check the code coverage of my tests from time to time. Is possible with a jest to generate the coverage folder without jest printing the coverage in the console?
I have not found out any cli…

distante
- 6,438
- 6
- 48
- 90
2
votes
0 answers
Angular 6 with Jest unit testing
I cloned a starter project using Angular 6 (https://github.com/KrunalLathiya/Angular6CRUDTutorial). I removed Karma and installed Jest instead. The site loads fine, but the unit test fails with this error:
Illegal state: Could not load the summary…

NJB
- 51
- 4
2
votes
0 answers
Mock array of objects using Jest
I am trying to write a unit test with Jest for a service in angular app and I have a question about how to mock a data. As part of my mock data I need to mock Array which has an interface like this
interface App {
Color: string;
…

AlreadyLost
- 767
- 2
- 13
- 28
1
vote
0 answers
How to set add my own globals when using jest-preset-angular/global-setup
I would like to be able to set a timezone for all tests to run in globally as outlined in this post. But still setup my jest.config.ts to leverage, either directly or indirectly, jest-preset-angular/global-setup.
It seems there is only one place in…

Paul
- 31
- 3
1
vote
0 answers
Jest encountered an unexpected token with custom angular library
I am trying to import my custom angular library from node_modules to my unit test, but I am getting this error.
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use…

Bendegúz Góczi
- 11
- 2
1
vote
1 answer
Jest ReferenceError on globally defined JS constants within Angular components
Today I've started using Jest to UnitTest some of our TypeScript files within our Angular project. After the initial Jest setup was done, creating a test for a pure TypeScript method in our util.ts was pretty straight-forward. Now I'm working on…

Kevin Cruijssen
- 9,153
- 9
- 61
- 135
1
vote
1 answer
ng-mocks giving error about imports with jest-preset-angular
Using ng-mocks 13.5.2 with jest-preset-angular 12 and @ngneat/spectator 11 I am getting the below error any time I try to use MockComponents or MockPipe in my spec file.
I'm not sure why this is happening.
Must use import to load ES Module:…

Gargoyle
- 9,590
- 16
- 80
- 145
1
vote
1 answer
Upgrading an angular 13 app with js-cookie stops running jest unit tests successfully
I have an angular app with version 13 which is using the external dependency js-cookie to set and get some cookies in the browser.
As a test environment I am using jest with jest-preset-angular. See all dependencies of the package.json below.
My…

JV3
- 872
- 2
- 9
- 21
1
vote
1 answer
Errors running tests using Angular v13 + Jest + ESM + NGXS
The migration from Angular v12 to v13 has been tough and while the app functions perfectly, the tests are still a problem on our side.
We have been running v12 tests using Jest with ESM (because we have a WebWorker and the import.meta.url requires…

jbzen
- 11
- 2
1
vote
1 answer
Angular: after moving from Karma to Jest, Error "Unrecognized CLI Parameters"
I updated my project from Angular 6.4 to Angular 7.1 and now running the script: ng test app-name --coverage gives me the error:
● Unrecognized CLI Parameters:
Following options were not recognized:
["main", "polyfills", "tsConfig"]
CLI…

Phil
- 7,065
- 8
- 49
- 91
0
votes
0 answers
Define `ts-jest` config under `globals` is deprecated
I have done migration of angular from 13 to 16.
Now I have the following config jest.prest.js
const nxPreset = require("@nx/jest/preset");
const esModules = ["@angular", "tslib", "rxjs"];
module.exports = {
...nxPreset,
globals: {
…

Walter White
- 976
- 4
- 12
- 29
0
votes
0 answers
Cannot find module '@angular/core/testing' | jest-preset-angular | Angular 14
While trying to run jest test after upgrading I am running into an issue where spec.ts (tests) are unable to find the @angular/core/testing module.
Image of the error
I've been searching on the internet for hours without a solution and cant seem to…

Mythcl
- 1
- 1