Questions tagged mocking

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

Jasmine SpyObj function is undefined

I am testing a component which includes a service. I want to mock the service. Following the documentation I have setup my mock like this: describe(‘DashboardComponent’, () => { let mockApplicationsService: jasmine.SpyObj<ApplicationsService>; const applicationServiceSpy = jasmine.createSpyObj(‘ApplicationService, [‘getApplications’]); beforeEach( waitForAsync(() => { TestBed.configureTestingModule({ declaration: [DashboardComponent], providers: [ { provide: ApplicationsService, useValue: {applicationsServiceSpy} } ] }).compileComponents(); }) […]

By Stephen Agwu
Categorized as angular, jasmine, karma-jasmine, mocking, spy Tagged , , , ,

write unit test case for a method which is returning promise in the form of array using jasmine karma

I am new to unit test cases. I have a method called ‘loadEsriModules’ which is calling from ngOnInIt(). below is the sample code for the same. ngOnInit() { debugger this.loadEsriModules().then(() => { this.mapManager.getMapInstance().subscribe(mapInstance => { debugger if (mapInstance) { this.mapInstance = mapInstance; } }); }); } Code of loadEsriModules Method. Application is working fine and […]

How to display mock data in html in Angular

I have created mock service file and I want to display in my html but not really sure how to make it display properly so I’ll be really appreciated If I can get any help or suggestion. <div class="container2"> <div class="header" style="height: 400px"> <div class="content3"> <div> <h1 class="kpi-title">90,346</h1>. // I’m trying to remove this hard […]

By Aase Zi
Categorized as angular, display, html, mocking, typescript Tagged , , , ,

I already mocked the service why still get error with not injecting dependency of service?

I am writing my unit test for my Angular component, in one component I called service which helping register reader in backend. In test, I mocked the service, but each time I still get error with not injecting dependency of the original service, why? My understanding is we should not consider those dependencies once I […]

Mocking an API route in a spy service (with Jasmine)

I’m attempting to mock out an API route in a spy service using Jasmine. I’m very new to Angular, Typescript, and Jasmine, so I can’t tell what I’m missing in my code, if I should insert the code within the beforeEach or in its own it(‘should do xyz…’), etc. I believe I should be running […]

By Bodrov
Categorized as angular, jasmine, mocking, spy, typescript Tagged , , , ,

ng-mocks error: MockBuilder/test.deep.spec.ts is missing from the TypeScript compilation

I simply the ng-mocks module like I have to previous projects but today I am getting the following error.: Firefox 78.0 (Linux x86_64) ERROR An error was thrown in afterAll Error: Module build failed (from ./node_modules/@ngtools/webpack/src/index.js): Error: ….node_modules/ng-mocks/examples/MockBuilder/test.deep.spec.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the ‘files’ […]

By BoxingMyEars
Categorized as angular, mocking, ngmock, testing Tagged , , ,

Mocking graph-ql requests

I’m frontend developer in angular typescript and I’m trying to figure out how to mock graphql requests(I’m using Apollo-angular). We decided to use graphql for new functionality in our app but it’s the first time we’ll be working with graphql. It’ll be a while before I’ll have requests ready so I wan’t to mock something […]

By Pawe Baku a
Categorized as angular, apollo, graphql, graphql-js, mocking Tagged , , , ,

How to mock an ElementRef that is passed into a method

I would like to write a test for a method that receives an ElementRef. I don’t find a way to mock the ElementRef, can anyone help? Thanks so much! exampleService.service.ts: export class exampleService { exampleMethod(elRef: ElementRef): string { const elWidth = elRef.nativeElement.offsetWidth; return elWidth; } } testfile.service.spec.ts: describe(‘ExampleService’, () => { let service: ExampleService; beforeEach(() […]

Angular mock service on component level

I have to mock service methods, which is injected on component level, not on module level. Here’s how my component looks like: @Component({ selector: ‘app-mycomponent’, template: ‘<some html content>’, … providers: [MyService], }) export class MyComponent implements OnInit { constructor(private myService: MyService) {} ngOnInit(): void { this.myService.myMethod(); } } and my spec file: define(‘MyComponent’, () […]

How to Unti Test Angular Components Depending on Firebase Service

I have a simple Create-User-Component that I want to unit test. The component depends on an Auth Service with a few methods, like ‘login, logout’ etc. The auth service imports both AngularFireAuth and AngularFireStore. It is the service that handles database interaction. The problem is that I can’t run my tests because I get a […]

1 2 3 5

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