мне нужно пройти тест на обслуживание вызова с использованием jasmine.jsкод используется для тестирования в жасмин
код ниже моего angular.js вызова службы:
var myApp = angular.module('myApp',[]);
app.controller('Myctrl', function($scope, $http) {
$http.get("http://www.w3schools.com/angular/customers.php")
.success(function(response) {$scope.names = response.records;});
});
Как пройти тест блока используя jasmine.js? Я попытался это, но она не увенчалась успехом:
describe('Myctrl', function() {
var $httpBackend, scope, createController, authRequestHandler;
// Set up the module
beforeEach(module('myApp'));
alert("Hello there!");
beforeEach(inject(function ($injector) {
// Set up the mock http service responses
alert("Hello there!");
$httpBackend = $injector.get('$httpBackend');
// backend definition common for all tests
alert("Hello there!");
authRequestHandler = $httpBackend.whenGET('GET', 'http://www.w3schools.com/angular/customers.php')
.respond(true);
// Get hold of a scope (i.e. the root scope)
$rootScope = $injector.get('$rootScope');
// The $controller service is used to create instances of controllers
var $controller = $injector.get('$controller');
createController = function() {
return $controller('Myctrl', {'$scope' : scope});
};
})
);
/*
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
*/
it('should fetch authentication token', function() {
//create expectation
$httpBackend.expectGET('GET','http://www.w3schools.com/angular/customers.php')
var controller = createController()
$httpBackend.flush();
expect(scope.names).toBeTruthy(true);
});
});
Я отредактировал сообщение и опубликовал код, который я пробовал до сих пор – NAND
Попробовал удалить все утверждения, повторяющие одно и то же. Надеюсь, теперь станет яснее –