How to use the @testing-library/angular/jest-utils.createMock 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 / examples / 05-component-provider.spec.ts View on Github external
test('renders the current value and can increment and decrement with a mocked jest-utils service', async () => {
  const counter = createMock(CounterService);
  let fakeCounterValue = 50;
  counter.increment.mockImplementation(() => (fakeCounterValue += 10));
  counter.decrement.mockImplementation(() => (fakeCounterValue -= 10));
  counter.value.mockImplementation(() => fakeCounterValue);

  const component = await render(ComponentWithProviderComponent, {
    componentProviders: [
      {
        provide: CounterService,
        useValue: counter,
      },
    ],
  });

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

@testing-library/angular

Test your Angular components with the dom-testing-library

MIT
Latest version published 3 months ago

Package Health Score

90 / 100
Full package analysis