How to use the @testing-library/angular/jest-utils.provideMock function in @testing-library/angular

To help you get started, we’ve selected a few @testing-library/angular examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github testing-library / angular-testing-library / src / app / app.component.spec.ts View on Github external
test(`should provide a mock greet service`, async () => {
  const component = await render(AppComponent, {
    declarations: [AppComponent],
    imports: [ReactiveFormsModule],
    providers: [provideMockStore(), provideMock(GreetService)],
  });
  const service: GreetService = TestBed.get(GreetService);

  component.click(component.getByText('Greet'));

  expect(service.greet).toHaveBeenCalled();
});
github testing-library / angular-testing-library / src / app / examples / 05-component-provider.spec.ts View on Github external
test('renders the current value and can increment and decrement with provideMocked from jest-utils', async () => {
  const component = await render(ComponentWithProviderComponent, {
    componentProviders: [provideMock(CounterService)],
  });

  const incrementControl = component.getByText('Increment');
  const decrementControl = component.getByText('Decrement');

  component.click(incrementControl);
  component.click(incrementControl);
  component.click(decrementControl);

  const counterService = TestBed.get(CounterService) as Mock;
  expect(counterService.increment).toHaveBeenCalledTimes(2);
  expect(counterService.decrement).toHaveBeenCalledTimes(1);
});

@testing-library/angular

Test your Angular components with the dom-testing-library

MIT
Latest version published 8 days ago

Package Health Score

92 / 100
Full package analysis