gpt4 book ai didi

javascript - Jasmine $location 测试

转载 作者:行者123 更新时间:2023-11-28 20:40:38 24 4
gpt4 key购买 nike

我尝试测试 $location 服务。这是我的 Controller

var recordType = $location.search().recordType;

还有我的测试:

describe('CorrectCtrl', function() {

var scope, httpMock;
var location, rootScope;
beforeEach(module('mainApp'));
beforeEach(inject(function($controller, $timeout, $location, $rootScope) {
scope = $rootScope.$new();
location = $location;
rootScope = $rootScope;
ctrl = $controller('myCtrl', {
$scope : scope,
$location : location
});
}));

it('location test', function(){
location.path("/PATH/");
location.search('recordType', '1');
expect(this.recordType).toBe('1');
});

如何使用 $location mock 设置我的 Controller 值?我想确保将 redordType 设置为 1;

最佳答案

尝试在 expect 函数调用之前调用 $rootScope.$digest()

关于javascript - Jasmine $location 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34871707/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com