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);
});
});
関連記事
server.js
server.js — javascript source code from the angular learning materials (angular/comprehensive-demo/server/server.js).
記事を読む →app.component.ts
app.component.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.component.ts).
記事を読む →app.config.ts
app.config.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.config.ts).
記事を読む →app.routes.ts
app.routes.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.routes.ts).
記事を読む →auth.guard.ts
auth.guard.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/core/guards/auth.guard.ts).
記事を読む →role.guard.ts
role.guard.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/core/guards/role.guard.ts).
記事を読む →