我想弄清楚如何使用業力+茉莉花測試服務承諾,但沒有成功。到目前爲止,這是我做過什麼,結果錯誤:angularjs 1和茉莉花,服務承諾測試
PhantomJS 2.1.1 (Mac OS X 0.0.0) The FetchData service should fetch data FAILED
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
fetchData服務:
module.exports = function($http) {
return {
getFoo: function(id) {
return $http.get('https://api/' + id)
.then(function(result) {
return result.data;
});
}
}
};
測試:
describe('The FetchData service', function() {
var dataFetcher;
beforeEach(angular.mock.module("myApp"))
beforeEach(inject(function(_dataFetcher_) {
dataFetcher = _dataFetcher_;
}));
it('should fetch data', function(done) {
var testData = function(res) {
expect(res.success).toBe(true);
};
var failTest = function(error) {
expect(error).toBeUndefined();
};
dataFetcher.getFoo(id)
.then(testData)
.catch(failTest);
});
});
我不知道是否有東西,我可能會丟失,可以幫我理解這一點,
謝謝!
https://docs.angularjs.org/api/ngMock/service/$httpBackend – Phil