"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
18
votes
2 answers
Equivalent of and.callThrough() in jest-preset-angular
Reading through this link i got to know that the equivalent of
and.callFake is mockImplementation and
and.returnValue is mockReturnValue.
Similarly is there an equivalent of and.callThrough() in jest-preset-angular?

radio_head
- 1,306
- 4
- 13
- 28
8
votes
3 answers
TypeError: Cannot read properties of undefined (reading 'ngModule')
Runing test I get this error
TypeError: Cannot read properties of undefined (reading 'ngModule')
I dont exactly know what is causing this error, but google said circular dependency issue but I am not sure where to start.
Using NX-monorepo with…

arshinfor
- 81
- 1
- 2
7
votes
2 answers
unexpected uncovered branch in jest coverage
I am testing an angular project with jest (using jest-preset-angular).
When collecting coverage, I get an uncovered branch and I don't understand why. I can reproduce the problem with 3 files.
some-dependency.ts
export class SomeDependency…

Sergio Mazzoleni
- 1,458
- 15
- 24
6
votes
5 answers
Jest Error: Cannot set base providers. After Angular v13 upgrade using 'ng test'
After upgrading Angular to v 13 when I try to run my tests in the jest environment I have an error:
Cannot set base providers because it has already been called
import 'jest-preset-angular/setup-jest';
Additionally, I configured Jest like it…

Geka
- 63
- 1
- 3
5
votes
1 answer
Cannot find module when using jest in nx
I have an nx workspace that I am trying to move to jest. At first I got an error about PointerEvent not being defined. the proposed workaround for that was to do an Object.defineProperty(window, 'PointerEvent'... My workspace has over 200…

Jason
- 1,316
- 13
- 25
4
votes
1 answer
Angular 13 + jest + Angular library not working
I'm trying to use jest in an Angular 13 project for testing.
I use jest-preset-angular with @angular-builders/jest.
I use ngx-pipes, which is a library that is not compiled for Angular 13. It works fine during normal Angular build. But in the jest…

dhcode
- 51
- 2
- 4
3
votes
1 answer
Cannot find module from setup-jest.js
I have an Angular library that I'm working to update from Angular 11 to 13. Jest ran fine in 11 and 12, but now I'm having a lot of trouble with v13. I've followed the steps outlined here
The error I'm getting is as follows:
Cannot find module…

Chris Perko
- 33
- 1
- 5
3
votes
1 answer
Configure `jest-preset-angular` with angular workspace
File structure:
- projects
- projectA
- tsconfig.app.json
- tsconfig.spec.json
- projectB
- tsconfig.app.json
- tsconfig.spec.json
- jest.config.js
- setup-jest.ts
- tsconfig.base.json
- tsconfig.json
I followed the installation…

Ambroise Rabier
- 3,636
- 3
- 27
- 38
3
votes
1 answer
jest-preset-angular not working with Angular 13 and ESM module
I'm using ESM modules with jest and when compiling with angular 12 jest-preset-angular worked great for me by listing @igniteui in the exclusion list. I upgraded to Angular 13, and the Next version of jest-preset-angular, but I can't get it working…

Gargoyle
- 9,590
- 16
- 80
- 145
3
votes
1 answer
How to setup tsconfig paths in jest.config.js. Angular 8. jest-preset-angular
I have absolute paths set up in my tsconfig that work as expected during serve however do not work for jest.
An example path looks like this:
"paths": {
"@shared": "src/app/shared/index.ts"
}
Then in a component I can use
import {…

AngularBoy
- 1,715
- 2
- 25
- 35
3
votes
2 answers
Testing an Angular method that uses Observable.forkJoin with Jest
I am trying to write a test for a component method that uses Observable.forkJoin. I have been all over the web and down some marbles rabbit holes, but in the end I think all I really need to do is mock the Observable forkJoin call and return fake…

Laura Slocum
- 7,696
- 2
- 11
- 9
3
votes
1 answer
Angular w/Jest: `verify()` vs.`expectOne()`?
I have a failing test that I'm not sure how to fix. The error messages I'm getting from Jest appear to be contradictory, and the problem relates to the behavior of two Angular HttpTestingController methods: verify() and expectOne().
The test in…

Jeremy S
- 51
- 1
- 5
3
votes
1 answer
ENONET error while running jest-preset-angular
I am trying to integrate jest for my angular project for unit testing.
I followed the instructions from this link.
I am facing a weird error as ENOENT: no such file or directory, open 'E:\source-code\packages\core\src\view\ng_module.ts' when i…

radio_head
- 1,306
- 4
- 13
- 28
2
votes
1 answer
Sometimes when I update the snapshots I got an Attribute __ngContext__
Sometimes when I update the snapshots I got an Attribute ngContext and for fix this problem I've to clean and install my node_modules to "fix" this issue.
I've to do this every time that I need to update a snapshot. I've already searched on multiple…

Rui Meireles
- 23
- 3
2
votes
1 answer
How to make jest only run testing for the files in src folder Angular?
I am learning how to setup jest testing in angular. I follow the instruction of jest-preset-angular.
I can successfully make the jest run in angular, but my app also has two submodules in the root, which jest gives a lot of errors on that. I would…

WenliL
- 419
- 2
- 14