0
Herhangi bir etkileşim olup olmadığını görmek için $httpBackend
'u değerlendirmenin bir yolunu arıyorum. Test noktasında bu noktada hiç çağrılmadığından emin olmak istiyorum. Buradaki belgeleri kontrol ettim: https://docs.angularjs.org/api/ngMock/service/ $ httpBackend ve cevabı bulamadınız. Bugüne kadar $ HTTP
class HomeService {
/*@ngInject*/
constructor ($http, $log) {
this.http = $http;
this.log = $log;
}
submit(keycode) {
this.log.log("submitting key code: " + keycode);
if (keycode === "") {
return false;
}
this.http.post(`/api/keycode/${keycode}`).then ((response) => {
this.log.log(response);
return true;
});
}
}
export default HomeService;
test vakası kullanılarak
Sınıf.
import HomeService from './home.service';
describe('HomeService',() => {
let homeService, $httpBackend;
beforeEach(inject(($injector) => {
$httpBackend = $injector.get('$httpBackend');
}));
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
describe('submit',() => {
it('submit empty keycode',() => {
homeService = new HomeService($httpBackend, console);
let value = homeService.submit("");
expect(value).to.be.false;
//valid no interactions with $httpBackend here!
});
});
});
httpBackend. – estus