我想对 angularjs 服务进行 e2e 测试,而不模拟 $http 调用。对 fsSvc.getSubject 的调用导致多个嵌入式异步调用,最终以调用回调函数结束,我已将调用完成。
不确定这是否行不通 - 如果 $http 没有被嘲笑,不应该真正调用它吗?:
it('should pass auth', function(done) {
inject(function (fsSvc) {
var cb = sinon.spy();
stubs.updateRecord = sinon.stub(dataSvc, 'updateRecord');
dataSvc.LO.famSrch.access_token_expires = false;
fsSvc.getSubject("abc", function(err, data) {
console.log("err:" + err);
done();
cb();
});
$timeout.flush();
expect(dataSvc.LO.famSrch.discovery).to.not.be.undefined;
expect(dataSvc.LO.famSrch.discovery.links).to.not.be.undefined;
expect(dataSvc.LO.famSrch.access_token).to.not.be.undefined;
expect(dataSvc.LO.famSrch.username).to.equal("test");
expect(dataSvc.LO.famSrch.password).to.equal(btoa("test"));
expect(dataSvc.LO.famSrch.access_token_expires).to.be.greaterThan(3600000);
expect(stubs.updateRecord.callCount).to.equal(1);
expect(stubs.updateRecord.args[0][1]).to.equal("localOption");
expect(cb.callCount).to.equal(1);
})
});