【发布时间】:2015-04-03 10:55:51
【问题描述】:
一直在做一些谷歌搜索,但找不到我这个小问题的答案。只是试图从我的控制器测试这段代码:
$scope.viewClientAssets = (id) ->
$location.path("/assets").search("client_id", "#{id}")
这反过来又返回这个网址:
这一切都很好,但是在单元测试时......一些假设: 我的规范设置正确,因为我有其他测试和期望工作得很好,所以这里是测试:
it 'checks if view client assets path is correct', ->
createController()
#gets rid of unnecessary function calls
flushRequests()
#calls the ctrl function with necessary args
$scope.viewClientAssets(clientData.client.id)
spyOn($location, 'path')
spyOn($location, 'search') #tried diff methods here such as
# and.returnValue(), .calls.any(), calls.all()
expect($location.path).toHaveBeenCalledWith("/assets")
expect($location.path.search).toHaveBeenCalled()
所有其他测试都通过了,但是当它被击中时,我收到以下错误:
TypeError: 无法读取未定义的属性“搜索”
控制台调试器告诉我:
$scope.createClientAsset = function(id) {
return $location.path('/assets/create').search("client_id", "" + id);
};
那条路径未定义?
有什么想法吗?
【问题讨论】:
-
你应该考虑改变接受的答案
标签: angularjs unit-testing jasmine