javascript - Angularjs unit testing with Karma -
having few issues testing directive - our application trying modular hence need module.exports exports angular module;
module.exports = angular.module('project', []) .config(function ($stateprovider) { $stateprovider .state('alive', { url: '/college', templateurl: 'dashboard.html', controller: 'collegectrl', authenticate: true }); }) .factory('college', require('./services/college.service.js')) .controller('collegectrl', require('./dashboard/college.controller.js')) .directive('collegetile', require('./dashboard/tile/tile.directive.js')) .run(function ($rootscope, sidefactory) { sidefactory.push({ 'priority': 1, 'icon': 'fa-th-large' }); });
directive looks this;
<div class="thumbnail" ng-click="openproject(college._id)"> <span>{{college}}</span> </div> </div>
the directive spec looks - note, templates loads in html templates;
'use strict'; describe('directive: tile', function () { var $compile; var $scope; // load directive's module , view beforeeach(module('ui.router')); beforeeach(module('project')); beforeeach(module('templates')); // create sidefactory beforeeach(module(function ($provide) { var sidefactory = { push: function () { } }; $provide.value('sidefactory', sidefactory); })); beforeeach(inject(function (_$compile_, _$rootscope_) { $compile = _$compile_; $scope = _$rootscope_.$new(); })); it("should validate true", function () { expect(true).tobe(true); }); });
i following error when running karma;
typeerror: 'undefined' not function (evaluating 'expect(true).tobe(true)')
karma config;
module.exports = function (config) { config.set({ // base path, used resolve files , exclude basepath: '', // testing framework use (jasmine/mocha/qunit/...) frameworks: ['jasmine', 'chai'], // list of files / patterns load in browser files: [ 'dev/assets/bundle.js', 'angular-mocks/angular-mocks.js', 'sample/client/*.html', 'sample/client/*.spec.js', 'client/**/*.html', 'client/**/*.spec.js' ], preprocessors: { 'client/**/*.html': ['ng-html2js'] }, nghtml2jspreprocessor: { // strip file path stripprefix: 'client/', prependprefix: 'college/', // setting option create single module contains templates // files, can load them module('foo') modulename: 'templates' }, // list of files / patterns exclude exclude: [], // test results reporter use // possible values: 'dots', 'progress', 'junit' reporters: ['progress', 'coverage'], coveragereporter: { type: 'html', dir: 'coverage' }, // enable / disable colors in output (reporters , logs) colors: true, // web server port port: 8080, // level of logging: log_disable || log_error || log_warn || log_info || log_debug loglevel: 'info', // enable / disable watching file , executing tests whenever file changes autowatch: true, // - ie (only windows) browsers: ['phantomjs'], // continuous integration mode // if true, capture browsers, run tests , exit singlerun: false }); };
Comments
Post a Comment