JSONレスポンスを返却するファクトリ用のテストキャスを作成しようとしています。AngularJSでフォームファクトリーを取得するためのテストケースの記述方法
エラー:[$インジェクター:UNPR]?http://errors.angularjs.org/1.4.1/ $インジェクター/ UNPR P0 =サービス・プロバイダ%20%3C-%エラーで20service (ネイティブ)
しかし、私はエラーを取得していますここ
は私のコードです:テストケースのため
(function() {
angular.module('uspDeviceService',[]).factory('getDevice', GetDevice);
GetDevice.$inject = ['$http'];
function GetDevice($http) {
getDeviceList = function() {
return $http.get("static/test-json/devices/device-list.json");
}
return {
getDeviceList: getDeviceList
}
}
}());
コード:
describe('Get Product test', function() {
beforeEach(module('uspDeviceService'));
var service, httpBackend, getDevice ;
beforeEach(function() {
angular.mock.inject(function ($injector) {
//Injecting $http dependencies
httpBackend = $injector.get('$httpBackend');
service = $injector.get('service');
getDevice = $injector.get('getDevice');
})
});
console.log('Injection Dependencies is done');
describe('get Device List', function() {
it("should return a list of devices", inject(function() {
httpBackend.expectGET("static/test-json/devices/device-list.json").respond("Response found!");
httpBackend.flush();
}))
})
});
誰もが私が間違っているつもりどこ、私を助けてくださいすることができ、私は、角度ユニットテストに新しいです..私に飛び出す
[OK]を行うことができます懸念している限り? –
@AnitaMehta:これは単体テストなので、JSONが常に正確に戻ってくると仮定したいと思うでしょう。実際のエンドポイントをテストする場合は、2つ目の注意が必要です。サードパーティ製のため、脆くなります。これらのテストは、エンドツーエンドのテストに最適です。 – Makoto
データがフォームファクトリに戻ってきているかどうかをチェックしたいのですが、それはすべて –