亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

單元測試AngularJS指令與templateUrl

單元測試AngularJS指令與templateUrl

慕妹3242003 2019-08-15 15:12:48
單元測試AngularJS指令與templateUrl我有一個templateUrl定義的AngularJS指令。我正在嘗試用Jasmine進行單元測試。根據以下建議,我的Jasmine JavaScript如下所示:describe('module: my.module', function () {     beforeEach(module('my.module'));     describe('my-directive directive', function () {         var scope, $compile;         beforeEach(inject(function (_$rootScope_, _$compile_, $injector) {             scope = _$rootScope_;             $compile = _$compile_;             $httpBackend = $injector.get('$httpBackend');             $httpBackend.whenGET('path/to/template.html').passThrough();         }));         describe('test', function () {             var element;             beforeEach(function () {                 element = $compile(                     '<my-directive></my-directive>')(scope);                 angular.element(document.body).append(element);             });             afterEach(function () {                 element.remove();             });             it('test', function () {                 expect(element.html()).toBe('asdf');             });         });     });});當我在我的Jasmine規范錯誤中運行它時,我收到以下錯誤:TypeError: Object #<Object> has no method 'passThrough'我想要的是模板加載原型 - 我不想使用respond。我相信這可能與使用ngMock而不是ngMockE2E有關。如果這是罪魁禍首,我該如何使用后者而不是前者呢?提前致謝!
查看完整描述

3 回答

?
慕慕森

TA貢獻1856條經驗 獲得超17個贊

我最終做的是獲取模板緩存并將視圖放在那里。事實證明,我無法控制不使用ngMock:

beforeEach(inject(function(_$rootScope_, _$compile_, $templateCache) {
    $scope = _$rootScope_;
    $compile = _$compile_;
    $templateCache.put('path/to/template.html', '<div>Here goes the template</div>');}));


查看完整回答
反對 回復 2019-08-15
  • 3 回答
  • 0 關注
  • 607 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號