国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

angular.js - angularjs requirejs karma directive templateUrl 測試失敗(哎呦喂)

瀏覽:133日期:2024-10-09 16:14:16

問題描述

目錄結構

--public----scripts--------*/.js // angular文件--test----*/.js // 測試文件--views----templates--------*/.html //directive templateUrl文件

requirejs test main文件

var allTestFiles = [];var TEST_REGEXP = /(-test).js$/i;Object.keys(window.__karma__.files).forEach(function(file) { if (window.__karma__.files.hasOwnProperty(file)) { if (TEST_REGEXP.test(file)) { allTestFiles.push(file); } }});require.config({ baseUrl: ’/base/public/scripts’, paths: { ’jquery’: ’../libs/jquery/dist/jquery’, ’angular’: ’../libs/angular/angular’, ’angularMocks’: ’../libs/angular-mocks/angular-mocks’, ’templates’: ’../../views/templates’ }, shim: { ’angular’: { deps: [’jquery’], exports: ’angular’ }, ’angularMocks’: { deps: [’angular’], exports: ’angular.mock’ }, ’templates/default/author-signature.html’: [’angular’] }, deps: allTestFiles, callback: window.__karma__.start});karma 配置文件

module.exports = function (config) { config.set({ basePath: ’’, frameworks: [’jasmine’, ’requirejs’], files: [ {pattern: ’public/libs/jquery/dist/jquery.js’, included: false}, {pattern: ’public/libs/angular/angular.js’, included: false}, {pattern: ’public/libs/angular-mocks/angular-mocks.js’, included: false}, {pattern: ’public/scripts/**/*.js’, included: false}, {pattern: ’views/templates/**/*.html’, included: false}, {pattern: ’test/**/*-test.js’, included: false}, ’test/test-main.js’ ], exclude: [ ’public/scripts/build-main.js’, ’public/scripts/require-config.js’, ’public/scripts/bootstrap.js’ ], browsers: [’Chrome’], reporters: [’progress’, ’html’, ’coverage’], htmlReporter: { outputFile: ’report/units.html’, pageTitle: ’Unit Tests’, subPageTitle: ’Unit tests with karma jasmine’ }, preprocessors: { ’public/scripts/**/*.js’: [’coverage’], ’views/templates/**/*.html’ : [’ng-html2js’] }, coverageReporter: { type : ’html’, dir : ’report/coverage/’ }, ngHtml2JsPreprocessor: { stripPrefix: ’views/’, stripSuffix: ’.html’, moduleName: ’templates’ } });}directive 測試文件

define([’angularMocks’, ’directives/default/author-signature’, ’templates/default/author-signature.html’], function () { describe(’Unit: Hello Directive’, function () { var $compile, $rootScope; beforeEach(function () { module(’angularApp’); module(’templates’); inject(function (_$compile_, _$rootScope_) {$compile = _$compile_;$rootScope = _$rootScope_; }); }); it(’should display the hello text properly’, function () { var elt = $compile(’<author-signature author='Plus'></author-signature>’)($rootScope); expect(elt.text()).toEqual(’Plus’); }); });});directive author-signature.js文件

define(’directives/default/author-signature’, [ ’angular-app’], function (angularApp) { angularApp.directive(’authorSignature’, function () { return { restrict: ’EA’, scope: {author: ’@’ }, replace: true, templateUrl: ’templates/default/author-signature’ }; });});author-signature.html

<h1>{{author}}</h1>angular-app.js文件

define(’angular-app’, [ ’angular’], function(angular) { var angularApp = angular.module(’angularApp’, []); return angularApp;});問題

將author-signature.js directive的templateUrl 換位template形式,測試成功;

通過查看源文件加載和調試,可查看到author-signature.html已轉為.js 且內容已加載到$templateCache中,如下截圖:angular.js - angularjs requirejs karma directive templateUrl 測試失敗(哎呦喂)

angular.js - angularjs requirejs karma directive templateUrl 測試失敗(哎呦喂)

但是測試無法通過,$compile編譯失敗。

求助

angular 在獲取$templateUrl內容時會默認的從$templateCache中獲取,而不直接獲取服務端的文件,以上描述中都以滿足了,但是還是無法$compile成功,感覺他沒有從$templateCache中獲取。不知道哪位大神能幫忙看下到底是哪里有點小問題?

問題解答

回答1:

OMG, I forget add $rootScope.$digest(); in test directive.That cause this directive scope’s attributes doesn’t change.

相關文章:
主站蜘蛛池模板: 手机看片1024久久精品你懂的 | 国产精品欧美一区二区在线看 | 真实国产乱人伦在线视频播放 | 久久国产视频一区 | 日本国产欧美色综合 | 国产精品日韩欧美一区二区 | 欧美一级毛片图 | 亚洲欧美精品一区 | 亚洲欧洲日产国码二区在线 | 亚洲欧美日本韩国综合在线观看 | 久久成人毛片 | 91精品全国免费观看 | 国产成人在线影院 | 一本色道久久88 | 99re5久久在热线播放 | 国产精品精品国产一区二区 | 日韩在线高清视频 | 步兵一区二区三区在线观看 | 国产第一草草影院 | 久久夜色精品国产 | 一色屋色费精品视频在线看 | 在线观看 国产 | 亚洲日本高清成人aⅴ片 | 亚洲国产精品久久卡一 | 成人18网址在线观看 | 亚洲网站视频在线观看 | 国产高清国产专区国产精品 | ririai99在线视频观看 | 亚洲精品区一区二区三区四 | 蝴蝶成人世界第八影院 | 午夜亚洲 | 新版天堂资源中文8在线 | 欧美日韩综合高清一区二区 | 99爱在线视频| 三级视频网站 | 欧美日韩在线观看精品 | 日本高清视频免费在线观看 | 国产乱码精品一区二区三上 | 台湾三级香港三级在线理论 | 国产精品久久久免费视频 | 欧美巨大另类极品videohd |