编译为html,如何编译模板HTML,超越.html()?

问题:我想访问我的模板中的表单,并根据验证,提交等进行测试。我相信我有正确的Karma/Jasmine测试设置,但我不知道如何访问表单。如何编译模板HTML,超越.html()?

测试module.view.html:

指令:

(function(){

"use strict";

angular.module('TestModule').directive('testDirective',Directive);

function Directive(){

return {

restrict: 'E',

controller: 'TestModuleController',

controllerAs: 'testModuleVm',

templateUrl: 'testModule/test-module.view.html'

};

};

})();

测试:

describe('Directive Tests',function(){

var element,$compile,$rootScope;

beforeEach(module('myTemplates'));

beforeEach(inject([

'$compile','$rootScope',

function($c,$rs){

$compile = $c;

$rootScope = $rs;

}

]));

it('should test an input element',function(){

element = $compile('')($rootScope);

$rootScope.$digest();

console.log(element); // Should see your template displayed

});

});

个karma.conf.js:

// Created May 04, 2016

module.exports = function(config) {

config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)

basePath: '',

// frameworks to use

// available frameworks: https://npmjs.org/browse/keyword/karma-adapter

frameworks: ['jasmine'],

// list of files/patterns to load in the browser

files: [

'vendor/angular/angular.js',

'vendor/angular/angular-mocks.js',

'test-module/test-module.view.html',

'test-module/test-module.module.js',

'test-module/test-module.controller.js',

'test-module/test-module.directive.js',

'test/test-module-tests.js',

],

// list of files to exclude

exclude: [

'vendor/bootstrap*',

'vendor/jquery*',

],

// preprocess matching files before serving them to the browser

// available preprocessors: https://npmjs.org/browse/keyword/karma- preprocessor

preprocessors: {

// karma-ng-html2js-preprocessor for templates in directives

'testModule/test-module.view.html': ['ng-html2js']

},

ngHtml2JsPreprocessor: {

moduleName: 'myTemplates'

},

// test results reporter to use

// possible values: 'dots', 'progress'

// available reporters: https://npmjs.org/browse/keyword/karma-reporter

reporters: ['progress'],

// web server port

port: 9876,

// enable/disable colors in the output (reporters and logs)

colors: true,

// level of logging

// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG

logLevel: config.LOG_INFO,

// enable/disable watching file and executing tests whenever any file changes

autoWatch: true,

// start these browsers

// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher

browsers: ['PhantomJS'],

// Continuous Integration mode

// if true, Karma captures browsers, runs the tests and exits

singleRun: false,

// Concurrency level

// how many browser should be started simultaneous

concurrency: Infinity

})

}

2016-05-17

westandy

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值