Skip to main content
InterviewHubPRO
Section Overview
Q192

Question 192 of 283

Part 8: Internationalization (i18n), Testing & DOM Directives (177 - 212)

68%
Angular Master (283 Qs)•Part 8: Internationalization (i18n), Testing & DOM Directives (177 - 212)

What is TestBed?

junior LevelCode ExampleDirectivesTesting

TestBed is an api for writing unit tests for Angular applications and it's libraries. Even though We still write our tests in Jasmine and run using Karma, this API provides an easier way to create components, handle injection, test asynchronous behaviour and interact with our application.

Practical Code Example

typescript
// TestBed: Primary Angular unit testing utility for configuring mocks and creating test components
import { TestBed } from '@angular/core/testing';
import { CounterComponent } from './counter.component';

describe('CounterComponent', () => {
  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [CounterComponent]
    }).compileComponents();
  });

  it('creates component', () => {
    const fixture = TestBed.createComponent(CounterComponent);
    expect(fixture.componentInstance).toBeTruthy();
  });
});