Questions tagged jestjs

Explore the latest questions and answers asked by our top developers.

provide mocked angular module library for unit test, Angular11

I am trying to write unit test for a component which is using simplebar-angular library. This library just creates a fancy scrollbar on ui. Due to some JEST reason, this library creating issues while running test. Since this libray only works for UI side so there is no .ts code. So i want to provide […]

By Raju
Categorized as angular, jestjs Tagged ,

Testing function inside of subscribe

Inside a function (ngOnInit in this case) I’m subscribing to an observable. When I get new data, I update another function with that data: ngOnInit(): void { this.observable$.subscribe({ next: (data) => { this.function(data) }, }); } function(data): void { console.log(data) } The problem comes when I need to test this. I’ve tried the approaches of […]

By hyena
Categorized as angular, jestjs, rxjs Tagged , ,

Does Angular’s DestroyAfterEach option affect the speed of Jest tests?

DestroyAfterEach is a new option that was added in Angular 12.1, and promises to greatly speed up test performance (details here). However, when making this change, I am not noticing any speed difference. I suspect this may be because I’m using Jest, which does not involve a browser. Is it expected that Jest does not […]

By Benjamin Kindle
Categorized as angular, angular12, jestjs, unit-testing Tagged , , ,

Can’t run tests in a Angular 9 project

I’m working on an Angular codebase (first time) and I want to test my components using the default test runner brought with Angular. Here, my issue is that I can’t run tests, I always get an error, the same for each test: ● Test suite failed to run File not found: jest-preset-angular/InlineHtmlStripStylesTransformer.js (resolved as: /path/to/project/client/jest-preset-angular/InlineHtmlStripStylesTransformer.js) […]

By botf
Categorized as angular, angular9, jestjs, ts-jest Tagged , , ,

Getting ‘TypeError: Cannot read property ‘ngModule’ of undefined’ when creating a unit test in angular

I am currently doing unit tests in a bigger project and for some reason I am getting the mentioned error when running my test. This is my code: it(‘first test, () => { expect(‘test’).toBe(‘test’); } But this fails. I imported the CommonModule and the component modules used. But even this simple test fails. Does anyone […]

By IonicMan
Categorized as angular, jasmine, jestjs, unit-testing Tagged , , ,

How to unit test code inside subscribe using jest

Hi can anyone provide me the example how we can unit test inside subscribe function using jest. I am using angular 12 and latest jest Source: Angular Questions

By Arpitha Mamidala
Categorized as angular, jestjs Tagged ,

Cannot spyOn on a primitive value thrown on mockRejectedValue

My test scenario should throw error if sign in fails is currently throwing an error Cannot spyOn on a primitive value; undefined given. I’m not sure why as I’m using it as against a mock function. Any idea why this happens? @Injectable({ providedIn: ‘root’, }) export class MockSupabaseClient { auth: MockSupabaseAuthClient; } export class MockSupabaseAuthClient […]

By methuselah
Categorized as angular, javascript, jestjs, typescript Tagged , , ,

JEST+ANGULAR Testing an @input() of a component

God day developers , I´m quite new about tests , thus in one of my basic implementations I´m trying to test this input in my nav-bar component , but for some reason i receive null. The design of my code for the child and parent components would be something like this: ===== child component HTML […]

By Enrique GF
Categorized as angular, jestjs, parent-child, unit-testing Tagged , , ,

Can’t resolve all parameters for SupabaseClient: (?, ?, ?) in unit test

How do I mock constructor parameters in Jest? I can’t seem to find anything on it. Here is my test: describe(‘SupabaseService’, () => { let service: SupabaseService; let mockSupabaseService: SupabaseClient; let user: User | undefined | null = { id: ‘test’, aud: ‘authenticated’, role: ‘authenticated’, email: ‘[email protected]’, email_confirmed_at: ‘2021-08-04T19:54:36.628041Z’, phone: ‘447700638931’, confirmed_at: ‘2021-08-04T19:54:36.628041Z’, last_sign_in_at: ‘2021-08-07T11:39:55.154822Z’, […]

By methuselah
Categorized as angular, javascript, jestjs, supabase, typescript Tagged , , , ,

Mocking imgur API calls in Jest unit test

How do I write a test for the upload and delete methods below which returns a mocked value? @Injectable() export class ImgurService { private readonly IMGUR_API_URL = ‘’; private readonly IMGUR_CLIENT_ID = ‘Client-ID’; constructor(private http: HttpClient) {} upload(upload: string | File, type = ‘base64’): Observable<ImgurResponse> { const headers = new HttpHeaders().set(‘Authorization’, `${this.IMGUR_CLIENT_ID}`); const formData = […]

By methuselah
Categorized as angular, javascript, jestjs, typescript Tagged , , ,
1 2 3 24

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us