Questions tagged [ng-mocks]

40 questions
4
votes
1 answer

Is it possible to preserve some methods from a mocked service with ng-mocks?

I'm adding tests to an angular project. There is a service which is getting some data from an API and create some business entity from this data. I mocked this service to test a component which depends on it, using ng-mocks. The original service…
jeremy-george
  • 1,171
  • 1
  • 9
  • 20
3
votes
1 answer

ng-mocks: NG0304: 'ng-mocks-ButtonComponent' is not a known element

I am using ng-mocks with Angular. While running the test case, I am getting below error console.error NG0304: 'ng-mocks-ButtonComponent' is not a known element (used in the 'i' component > template): If 'ng-mocks-ButtonComponent' is an Angular…
3
votes
1 answer

Angular shallow rendering snapshots in unit tests fails with strange behavior

I'm currently facing a strange behavior on my Angular (14) shallow rendering snapshots in unit tests (Jest 28). Sometimes my snapshot tests are failing, depending if I run them individually or as bundle. The reason of failure is the difference…
N33D
  • 135
  • 1
  • 7
3
votes
1 answer

provideMockStore with MockBuilder in ng-mocks

How to overrider the selector value in MockBuilder provided with provideMockStore In general with Testbed beforeEach(() => { TestBed.configureTestingModule({ declarations: [ ABCComponent, MockComponent(YYYComponent) …
3
votes
1 answer

How can I manipulate providers in specific tests using ng-mocks?

I started using ng-mocks a couple weeks ago because I thought it was designed with this case in mind but for the life of me I can't figure out how to implement it. In short, can the value of mock providers be changed in nested describes/tests after…
iamsar
  • 1,080
  • 2
  • 15
  • 28
3
votes
3 answers

Angular mock Spec

I am using ng-mocks this way - import { MockDirective, MockComponent, ngMocks } from 'ng-mocks'; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ MockComponent(ComponentName), ], …
Jay
  • 2,485
  • 6
  • 28
  • 34
3
votes
1 answer

Mock Angular Router with Spectator

I am using Spectator to write my Angular 8 tests and Jest to run them. I am new to frontend unit testing, so I may have overlooked something simple; any ideas are welcome. I have the following method (in Typescript) that returns a boolean, based on…
Babyburger
  • 1,730
  • 3
  • 19
  • 32
2
votes
1 answer

How to add ng-mocks to a fresh Angular 15 project

I recently created a new Angular project using the latest Angular 15 CLI. Now I want to add ng-mocks to it. I can install the dependency, but there is no longer a test.ts file where I can add the configuration for ng-mocks. When I add the file…
jan.vdbergh
  • 2,129
  • 2
  • 20
  • 27
2
votes
2 answers

How do you reset jasmine spy calls when using autoSpy with ng-mocks?

I am using ng-mocks for mocking and so far everything works OK with a few exceptions of some quirks. I'm using autoSpy to spy every method automatically so I don't have to manually spy on functions. So according to the documentation, I've got, in my…
LocustHorde
  • 6,361
  • 16
  • 65
  • 94
2
votes
1 answer

ng-mocks MockBuilder / MockRender with injected (real) service

I am attempting to independently test a child component that requires a FormGroup as input, as the child represents a section on the parent form. We use an in-house framework that relies on an entity / entity service hierarchy to automagically build…
Xyn
  • 41
  • 3
2
votes
1 answer

MockComponent still includes the actual component

In my unit test I'm doing the following (via @ngneat/spectator): const createComponent = createComponentFactory({ component: AppComponent, detectChanges: false, declarations: MockComponents(IgxToastComponent,…
Gargoyle
  • 9,590
  • 16
  • 80
  • 145
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
0 answers

ng-mocks not instantiating tested component

I have a Component which I want to test (not mock). It has some public and private fields like destroy$ = new Subject(); which have no @Input. When I call MockRender and get the component via fixture.point.componentinstance, the fields are…
Phil
  • 7,065
  • 8
  • 49
  • 91
2
votes
1 answer

Angular and Jasmine Test firebase auth with google provider cannot read property

I'm starting with unit testing and it's hard to test a method that login using firebase auth. I've tried it in many ways and tested it in several means as you can see in the code comments and in most cases it always returns: TypeError: Cannot read…
2
votes
2 answers

How to check inner component's method is called during tests?

I have a component (MapComponent) that calls external API via HexesService. Results of Data of this API call are loaded to some buttons (View Map, Edit Map). I have another internal component (HexesComponent) and clicking on a View button makes a…
Budda
  • 18,015
  • 33
  • 124
  • 206
1
2 3