0
爲什麼此測試失敗,並且:預期爲null是「這是一方」。 我試圖嘲笑派對服務返回假價值,但它不工作。使用茉莉花正確嘲笑服務的角度
'use strict';
describe("test controller: ConsultationService", function() {
var scope;
var controller;
var partyService = {
get: function() {}
}
beforeEach(angular.mock.module('aureus'));
beforeEach(function() {
module(function($provide) {
$provide.value('partyService', partyService);
});
});
beforeEach(inject(function ($rootScope, $controller, $q) {
spyOn(partyService, 'get').and.callFake(function() {
var deferred = $q.defer();
deferred.resolve('this is a party');
return deferred.promise;
});
scope = $rootScope.$new();
controller = $controller('ConsultationController', { $scope: scope, $partyService: partyService });
}));
it("scope consultation should be defined", function() {
expect(scope.consultation).toBe(null);
expect(scope.party).toBe('this is a party');
});
});
與此控制器
aureus.controller('ConsultationController',
['$scope', '$location', '$http', 'ngProgress', 'partyService', 'ConsultationService',
function ($scope, $location, $http, ngProgress, $partyService, consultationService) {
$scope.consultation = null;
$scope.party = null;
$scope.urlData = Api.parseUrl($location.$$absUrl, '/comments/{account}');
$partyService.get($scope.urlData.account).then(function (party) {
$scope.party = party;
});