簡體   English   中英

用於angularjs ui-route的mocha chai測試用例

[英]mocha chai test case for angularjs ui-route

我需要通過mocha chai覆蓋angularJs配置文件

在此輸入圖像描述

我試過了

it('should load the page.', inject(function ($location, $rootScope, $state, $httpBackend) {
    $httpBackend.whenGET('scripts/select-line-module/views/select-line.html').respond('<div/>');
    var state = $state.get('selectLine');
    $rootScope.$digest();
    assert.isDefined(state.templateUrl()); 
    expect(state.templateUrl).toBe('scripts/select-line-module/views/select-line.html');
}));

我能夠覆蓋templateUrl函數但測試用例失敗錯誤:undefined不是函數

在此輸入圖像描述

我覺得我很親近,但我在這里缺少什么?

你的斷言和期望發生了變化。 您必須斷言函數templateUrl已定義,並期望函數返回為字符串。

assert.isDefined(state.templateUrl); 期望(state.templateUrl())砥( '腳本/選擇行模塊/視圖/選擇-line.html');

但是,您可以檢查狀態是否已定義? 我認為這可能是不確定的。

我做到了

it('should load the page.', inject(function ($state) {
    var state = $state.get('selectLine');
    assert.isDefined(state.templateUrl()); 
    expect(state.templateUrl()).to.equal('scripts/select-line-module/views/select-line.html');
}));

這適合我

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM