我的服务中有以下方法
initialStateData() {
if (!this.hasLoaded()) {
console.log('do you see me?? 1');
// next line erroring out here on..
console.log('do you see me?? 2');
this._dataLoadPromise = new Promise((resolve, _reject) => {
this.actionManager.initLoad();
const promises = [];
promises.push(this.getFacs());
promises.push(this.getRoles());
promises.push(this.getParams());
promises.push(this.getSecurityRights());
Promise.all(promises).then(() => {
this.actionManager.completeInitialLoad(this.initialState, this.initialStaticData);
this.fac$.subscribe((fac) => this.loadFacBasedData(fac, false));
this.fg$.subscribe((fg) => this.loadFacBasedData(fg, true));
this.rightSets$.subscribe((rightSets) => this.getUsersForSecRights(rightSets));
this._hasLoaded = true;
resolve();
})
.catch((err) => {
this.actionManager.dispatchAction('ERROR_OCCURRED', 'in initialStateData()');
this.HandleError(err);
});
});
}
}
我的测试用例如下:
describe('initialStateData', () => {
it('makes expected calls', () => {
const actionManagerStub: ActionManager = TestBed.get(ActionManager);
service.initialStaticData = { rights: [{ GroupKey: 33, GroupName: 'Manager', Description: null, GroupIsShown: true }], roles: [{ roleId: 'a0986679', roleName: 'admin' } ] } ;
spyOn(service, 'getSecurityRights').and.callThrough();
spyOn(actionManagerStub, 'initLoad');
spyOn(actionManagerStub, 'completeInitialLoad').and.callThrough();
spyOn(actionManagerStub, 'dispatchAction').and.callThrough();
(<jasmine.Spy>service.initialStateData).and.callThrough();
service.initialStateData();
expect(service.getRightSetsForRoles).toHaveBeenCalled();
expect(service.getLastCoders).toHaveBeenCalled();
expect(service.getDischarges).toHaveBeenCalled();
expect(service.getGrouperDescription).toHaveBeenCalled();
expect(service.getUsersForRightSets).toHaveBeenCalled();
expect(actionManagerStub.initLoad).toHaveBeenCalled();
expect(actionManagerStub.completeInitialLoad).toHaveBeenCalled();
expect(actionManagerStub.dispatchAction).toHaveBeenCalled();
});
});
我在控制台中看到了这一点
do you see me?? 1
,但在控制台do you see me?? 2
中也看到了以下错误
context.js:232 未处理的承诺拒绝:调度失败:您是否忘记配置您的商店?
如何让茉莉花从测试用例执行到 new Promise((resolve, _reject)) 块中?
任何帮助表示赞赏..