Open asnowwolf opened 7 years ago
We can use InMemoryDbService as a MockBackend in unit tests. It is very convenient in most simple scenes.
In this scenario we need:
Workground:
beforeEach(() => { TestBed.configureTestingModule({ imports: [ HttpModule, InMemoryWebApiModule.forRoot(MockDbService), ], providers: [ProgramApi, InMemoryBackendService], }); }); let api: ProgramApi; let backend: InMemoryBackendService; beforeEach(inject([ProgramApi, InMemoryBackendService], (_api_: ProgramApi, _backend_: InMemoryBackendService) => { api = _api_; backend = _backend_; })); afterEach(() => { backend['resetDb'](); }); it('should create', () => { expect(api).toBeTruthy(); }); ...
I like this approach, but where are you getting ProgramApi (I realize this isn't part of angular)?
It's a service of the application.
We can use InMemoryDbService as a MockBackend in unit tests. It is very convenient in most simple scenes.
In this scenario we need:
Workground: