S SmartDocs
Série: angular typescript 28 lignes · Mis à jour 2026-02-03

customer.service.spec.ts

angular/examples/week07-08/customer.service.spec.ts

// @ts-nocheck
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { CustomerService } from './customer.service';

describe('CustomerService', () => {
  let service: CustomerService;
  let http: HttpTestingController;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [HttpClientTestingModule],
    });
    service = TestBed.inject(CustomerService);
    http = TestBed.inject(HttpTestingController);
  });

  afterEach(() => {
    http.verify();
  });

  it('loads customers and updates signal', () => {
    const mock = [{ id: '1', name: 'Ada Lovelace', email: 'ada@example.com', status: 'active' }];
    service.load().subscribe();
    http.expectOne('/api/customers').flush(mock);
    expect(service.customers()).toEqual(mock);
  });
});

Articles liés