我正在使用NativeScript 6.4.1和Angular 8.2.0编写应用程序。我正在使用业力和茉莉花来编写单元测试。
我的一项服务中有一个返回promise的功能,我想编写一个单元测试来测试该功能。
我在这里阅读了文档:https://angular.io/guide/testing#service-tests
我应该能够使用'done()'函数通过异步调用编写测试。
我的诺言没有在测试中被调用
describe('SsoAuthenticationService', () => {
let service: SsoAuthenticationService;
beforeEach(nsTestBedBeforeEach([], [SsoAuthenticationService]));
beforeEach(() => {
service = TestBed.get(SsoAuthenticationService);
});
it('getHttpHeader - token data exisits and it is valid', (done: DoneFn) => {
const result = service.getHttpHeader();
console.log('1'); //called
result.then((res) => {
console.log('2'); //not being called
expect(res).not.toBeNull(); //not being called
done();
});
console.log('3'); //called
服务:
export class SsoAuthenticationService {
public getHttpHeader(): Promise<string> {
return Promise.resolve('a');
}
}
如何使单元测试正常工作并运行Expect块?