Thursday 15 May 2014

javascript - Failed to instantiate module error while running angularjs unit tests using karma html2js preprocessor -



javascript - Failed to instantiate module error while running angularjs unit tests using karma html2js preprocessor -

i trying hands on karma preprocessor template loaded in unit tests.

my angularjs unit tests directive throwing 'failed instantiate module error' while running tests. using karma html2js preprocessor in karma.conf.js getting template in directive unit test.

karma.conf.js

config.set({ preprocessors: { 'components/navbar/templates/navbar.htm': ['ng-html2js'] }, files: [ 'scripts/angular-mocks.js', ... ... 'client/components/navbar/templates/navbar.htm' ], nghtml2jspreprocessor: { modulename: 'templates' }

navbar_testcase.js

describe("navbartesting", function () { var template; beforeeach(module('templates')); beforeeach(function () { module("navbar"); inject(function ($rootscope, $compile, $httpbackend, $injector, $localstorage, $state, $templatecache, usersession, appconfig) { http = $httpbackend; $httpbackend = $injector.get('$httpbackend'); ... .... }); }); });

while running above unit test error 'failed instantiate module 'templates'' thrown. might problem in this? having physical path defined have 'templates' module in karma config file?

with config, possible create template. downside create view.tpl.html , not test.tpl.html

config.set({ autowatch: true, basepath: '../', browsers: ['chrome'], frameworks: ['jasmine', 'requirejs'], reporters: ['progress'], plugins: [ 'karma-chrome-launcher', 'karma-phantomjs-launcher', 'karma-jasmine', 'karma-requirejs', 'karma-ng-html2js-preprocessor-requirejs' ], files: [ // app-specific code {pattern: 'src/**/*.js', included: false}, // 3rd party code {pattern: 'lib/**/*.js', included: false}, //test files {pattern: 'test/unit/**/*.js', included: false}, 'test/test-main.js', '**/test.tpl.html', '**/view.tpl.html' ], nghtml2jspreprocessor: { enablerequirejs: true, modulename: 'templates', cacheidfrompath: function (filepath) { console.log('path=' + filepath.replace(/^.*[\\\/]/, '')); homecoming filepath.replace(/^.*[\\\/]/, ''); }, }, exclude: [ 'src/main.js' ], preprocessors: { '**/*.html': ['ng-html2js'] }

javascript angularjs unit-testing karma-jasmine

No comments:

Post a Comment