Questions tagged [ng-mocks]

40 questions
1
vote
0 answers

Angular unit test problem with ngModel using ng-mocks

I have a specific issue with using ng-mocks and testing ngModel. The following is my unit test, with marked line which fails: it('should not move focus, and should delete current input value when backspace clicked inside filled input',…
Tomas J
  • 21
  • 4
1
vote
0 answers

Weird behavior after updating ng-mocks, Testbed.create component behavior changes after the update

I was updating ng-mocks from 13.0.0-alpha.6 to 14.11.0, and I noticed something strange, we have wrapper component that we use for some testing, our testbed configuration looks like this TestBed.configureTestingModule({ declarations: [ …
Munzer
  • 2,216
  • 2
  • 18
  • 25
1
vote
2 answers

Unit Testing - Mocking a Subject using ng-mocks

I am trying to add unit tests to my angular component which is dependent on a service. The component is subscribing to a flag variable in the service. I am trying to use ng-mocks to mock the service using the MockProvider. And while trying to set…
1
vote
1 answer

Angular test - set up a spy on a function of the SUT component before the component is created by TestBed

I have an Angular component I am writing tests for. The SUT component has a function I need to spy on (not ideal as noted further below). I want to set up the TestBed so that the function already has a spy assigned when TestBed creates the…
Rob
  • 73
  • 8
1
vote
1 answer

How to Mock a the same method with different input/returns with NgMocks?

I'm doing some tests, and using ng-mocks for our store as well as ng-mocks for the testing. I'm currently one service, that is subscribing to one selector of the store: async initialize() { const elementId = await…
J4N
  • 19,480
  • 39
  • 187
  • 340
1
vote
1 answer

ng-mocks MockDirectives(MatTooltip) Error: NG0300: Multiple components match node with tagname button

I'm facing an issue with failed unit tests: Error: NG0300: Multiple components match node with tagname app-progress-button. Error: NG0300: Multiple components match node with tagname button Error: NG0300: Multiple components match node with…
Rebai Ahmed
  • 1,509
  • 1
  • 14
  • 21
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

How to mock an object and verify a given parameter was provided to this mock

I'm trying to test an HttpInterceptor, with the help of ng-mocks: @Injectable() export class AuthTokenInterceptor implements HttpInterceptor { constructor(private store: Store) {} intercept(req: HttpRequest, next:…
J4N
  • 19,480
  • 39
  • 187
  • 340
1
vote
3 answers

ng mocks library to test form component ( template driven form )

I have been going through a ton of documentations including their own ng-mocks library here . I am relatively new to this library. PS: I know other libraries like spectator to do this, or using plain jasmine / jest, but i was trying the same using…
1
vote
1 answer

How to test component which extends base component with ng-mocks

I have CakeItemContainerComponent which extends ItemContainerComponent and I try to test it with ng-mocks. Here what I'm trying to do: @Component({ selector: 'app-item-container', template: '' }) export class ItemContainerComponent implements…
1
vote
2 answers

How to test that an NGXS action has been dispatched, amongst some other tests?

I'm using NGXS with a facade pattern(basically, components have access to an angular service, and the angular service reference the store, dispatch the method if needed. I'm in the process of testing one method of my service. This method: Make an…
J4N
  • 19,480
  • 39
  • 187
  • 340
1
vote
0 answers

Angular test jasmine, ng-mocks

I don't understand why my service is not getting called.. in my BooklistComponent, I call ngOnInit which calls initBooks() which calls the bookApiService getAll() method... My Setup: beforeEach( waitForAsync(() => { …
MMMM
  • 3,320
  • 8
  • 43
  • 80
1
vote
1 answer

Mocking generated API service

In our Angular application, we are using services generated from API and we're facing issues with the unit tests for components or custom services that utilize them. // Generated code getCurrentConnection(observe?: 'body', reportProgress?: boolean,…
mat.hudak
  • 2,803
  • 2
  • 24
  • 39
1
vote
1 answer

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…
BoxingMyEars
  • 43
  • 1
  • 5
1
vote
1 answer

beforeEach dies without error on MockRender call

I am testing a component using ngMocks and my spec keeps failing with "formGroup expects an instance of type FormGroup please supply one". I was able to validate that component is actually never set. In fact every single line after the marked one…
Chund
  • 355
  • 2
  • 15