Questions tagged [angular-jest]

27 questions
16
votes
3 answers

Mocking Observable to throw error in Jest

I am trying to mock the PUT call of HttpClient of Angular to throw error. I am using throwError for it. It isn't working. What should I change to make it throw the error and call the handleError method? I am using Jest. it(`should call the…
Pritam Bohra
  • 3,912
  • 8
  • 41
  • 72
3
votes
1 answer

Is there a way to bring number of unit tests under coverage in Sonarqube report for Angular-Jest project?

I have run sonar for Angular-Jest project and got the unit test coverage but am not getting number of unit tests. My Sonar properties,(sonarqube version -…
RGA
  • 303
  • 3
  • 11
2
votes
1 answer

Create mocked service (object) with one method returning a value

In an Angular environment, how can I very easily create in a Jest environment a mocked service for a service object returning a specific value? This could be via Jest of ng-mocks, etc. An oversimplified example: // beforeEach: // setup an Angular…
tm1701
  • 7,307
  • 17
  • 79
  • 168
2
votes
1 answer

Angular Jest tick not working for debounceTime on RxJS 7

I updated my angular application to Angular 13 and everything kept working fine. Then I updated RxJS from 6.6.0 to 7.4.0. After that some unittest failed. Pseudo test: it('should test some async', fakeAsync(() => { …
Robin Dijkhof
  • 18,665
  • 11
  • 65
  • 116
2
votes
1 answer

Angular jest doesn't understand import path after update to 27

This is a weird error. So I updated jest to 27 and all stopped working It seems to have issues with import paths. So the following import { something } form 'src/app/components/.....'; doesn't work, but this does: import { something } from…
Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
2
votes
1 answer

Should Match Snapshot jest unit testing with Angular

Trying to do the Snapshot test with Jest in angular 10 and test application is failed expect(received).toMatchSnapshot() Snapshot name: `DestinationComponent Should Match Snapshot 1` - Snapshot - 5 + Received + 5 @@ -12,15…
San Jaisy
  • 15,327
  • 34
  • 171
  • 290
1
vote
0 answers

Strange Jest Cache Behavior in GitLab CI - Duplicate Component Bundles

I successfully integrated Jest cache with our GitLab jobs, and everything worked well. I noticed a significant performance improvement and verified that the cache object met my expectations. However, I encountered an issue where the Jest cache…
Munzer
  • 2,216
  • 2
  • 18
  • 25
1
vote
0 answers

Angular Jest unit test failed TypeError: Cannot read properties of undefined (reading 'subscribe')

I'm new to Jest testing in Angular, and I'm facing an issue with one of my component tests. The test is failing with the following error message: Type Error: Cannot read properties of undefined (reading 'subscribe') I have an…
1
vote
1 answer

Cannot read property 'matches' of undefined When installing Jest in Angular

I want to use jset in my angular project. when I run the following command: npm install jest --save-dev Get the following error : npm ERR! Cannot read property 'matches' of undefined NOTE: before install jest I remove completely Karam with the…
AR Second
  • 582
  • 1
  • 6
  • 25
1
vote
0 answers

Unable to override provider in angular 9

When trying to override provider in test case using, Testbed.overrideProvider it doesn't actualy override anything. It used to work fine angular 9 with jasmine, not sure what has changed in angular 9 which has broke it. Any help will be…
Rushi patel
  • 522
  • 7
  • 17
1
vote
1 answer

Angular 8 with Jest - 'jasmine' has no exported member 'SpyObj'

I have an Angular CLI project that has the default Karma test runner. I used this tutorial to replace Karma with Jest and notice some tests are passing some failing. For example, declaring a variable on test level: let mockObj:…
d-man
  • 57,473
  • 85
  • 212
  • 296
1
vote
1 answer

Angular Jest testing `Cannot find name 'By'.`

I am using Jest.JS with Angular. When I try to test the directive, I get the error: Cannot find name 'By'. src/app/directives/error-highlighter.directive.spec.ts:33:46 - error TS2304: Cannot find name 'By'. 33 inputEl =…
user2024080
  • 1
  • 14
  • 56
  • 96
0
votes
0 answers

How do I resolve Jest coverage reports by my source files, and not compiled modules, in an Angular + Typescript/ECMA project?

So I have a working base Angular project, and some simple generated tests. I've added Jest, ts-jest and jest-preset-angular, and I can get the correct number of passing tests on running ng test. I've tried various jest configs from the docs at…
frackham
  • 406
  • 4
  • 15
0
votes
0 answers

Getting error while running Jest test case in Angular

I created an Angular application, uninstalled Jasmine and Karma and installed Jest. I have done all the steps correctly. Whenever I run the jest tests it gives me an error: "error TS5023: Unknown compiler option 'files'". I am unable to figure out…
Akrit
  • 91
  • 1
  • 4
0
votes
0 answers

Mock Component used in MatDialog

I have two libraries/modules with one component Each. One Component (MainComponent) uses the other (DialogComponent) in a MatDialog open Statement. The DialogComponent uses a Service (PermissionsServie) that uses MsalModule. When i mock and provide…
Andresch Serj
  • 35,217
  • 15
  • 59
  • 101
1
2