karma-runner

How to test directives that use templateUrl and controllers?

元气小坏坏 提交于 2019-12-21 02:21:07
问题 EDIT: after asking the question, i'm now editing this to elaborate on my findings. My app is modularized using directives. I'm writing my directives such that they (1) create their own scope (2) use templateUrl, and (3) do most of the logic and server data fetching in their controller. The question is how to unit test it, using Mocha with Karma. 回答1: a test is written for each directive. Since the directive uses templateUrl, I used html2js. the html key should be included as a module - that

karma test runner not running any tests

▼魔方 西西 提交于 2019-12-20 18:04:50
问题 I'm using karma with jasmine and followed online guide by installing using npm install --save-dev karma and other necessities i ran ./node_modules/karma/bin/karma start and karma start karma.conf.js which opened up a external chrome browser showing that karma is connected. I wrote a simple unit test for one my functions it seems its not running any tests at all This is my karma config file. // Karma configuration module.exports = function(config) { config.set({ // base path, that will be used

Conditionally ignore individual tests with Karma / Jasmine

≯℡__Kan透↙ 提交于 2019-12-20 17:25:04
问题 I have some tests that fail in PhantomJS but not other browsers. I'd like these tests to be ignored when run with PhantomJS in my watch task (so new browser windows don't take focus and perf is a bit faster), but in my standard test task and my CI pipeline, I want all the tests to run in Chrome, Firefox, etc... I've considered a file-naming convention like foo.spec.dont-use-phantom.js and excluding those in my Karma config, but this means that I will have to separate out the individual tests

Generate jasmine report using Karma Runner

妖精的绣舞 提交于 2019-12-20 16:50:11
问题 I want to obtain a report of all successful jasmine specs runned with karma, something like you obtain when using jasmine alone. Is there anyway to achieve this? 回答1: Try this quick plugin I wrote: https://github.com/dtabuenc/karma-html-reporter 回答2: tl;dr Yes, but it's non-trivial, and even more so if you want --auto-watch . So, basically, no :-( Blame it on lib/reporters/Progress.js, which swallows successful test results and spits out a summary line for each browser. If you're determined,

How to get better test reports in the console?

北慕城南 提交于 2019-12-20 16:11:25
问题 I have a fairly simple karma.config.js file basePath = '../'; files = [ JASMINE, JASMINE_ADAPTER, 'js/lib/angular*.js', 'test/lib/angular/angular-mocks.js', 'js/**/*.js', 'test/unit/**/*.js' ]; autoWatch = true; browsers = ['PhantomJS']; When I run karma start config/karma.conf.js --single-run I'm getting the following output $ karma start config/karma.conf.js --single-run [2013-06-24 23:47:08.750] [DEBUG] config - autoWatch set to false, because of singleRun INFO [karma]: Karma server

Javascript.confirm() and Angularjs Karma e2e test

谁说胖子不能爱 提交于 2019-12-20 12:23:19
问题 I have an Angularjs application that uses simple javascript confirm before executing some actions. Controller: function TokenController($scope) { $scope.token = 'sampleToken'; $scope.newToken = function() { if (confirm("Are you sure you want to change the token?") == true) { $scope.token = 'modifiedToken'; } }; } View: <div id="tokenDiv"> Token:{{token}} <button ng-click="newToken()">New Token</button> </div> Now I want to have an end to end test to check the token is being replaced correctly

generator-karma does not satisfy its siblings' peerDependencies requirements

我与影子孤独终老i 提交于 2019-12-20 10:23:22
问题 The same notorious error npm ERR! peerinvalid The package generator-karma does not satisfy its siblings' peerDependencies requirements! npm ERR! peerinvalid Peer generator-angular@0.7.1 wants generator-karma@~0.6.0 npm ERR! peerinvalid Peer generator-angular-ui-router@0.5.3 wants generator-karma@~0.5.0 npm ERR! System Darwin 12.5.0 npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "generator-angular" npm ERR! cwd /Users/dmitrizaitsev/Dropbox/Priv/APP/my-yo-project npm ERR! node -v

AngularJS + Karma + Ng-html2js => Failed to instantiate module …html

荒凉一梦 提交于 2019-12-20 09:48:52
问题 I can't make Karma working for directives that have external templates. Here is my karma configuration file : preprocessors: { 'directives/loading/templates/loading.html': 'ng-html2js' }, files: [ ... 'directives/loading/templates/loading.html', ] ngHtml2JsPreprocessor: { prependPrefix: '/app/' }, In the directive file : ... templateUrl: '/app/directives/loading/templates/loading.html' ... In the spec file : describe('Loading directive', function() { ... beforeEach(module('/app/directives

Karma Webpack - Error: Cannot find module “./test/utilities.js”

情到浓时终转凉″ 提交于 2019-12-20 06:14:56
问题 I'm using Karma Webpack for the unit tests of a project. When I run karma start , I have this error: Error: Cannot find module "./test/utilities.js" at /myproject/test/campaign.test.js:49 <- webpack:///test/campaign.test.js:3:0 Here is the content of my file campaign_test.js : "use strict"; var utilities = require('./test/utilities.js'); describe(" campaign unit tests", function () { var error = null; var user = null; utilities.initParse(); }); Here is the karma.conf.js file: var webpack =

Karma tests fail in chrome but pass in phantomjs

那年仲夏 提交于 2019-12-20 03:07:55
问题 I have been battaling with this for a bit now and cant seem to find the right solution, i am running an ionic 2 project that uses angular 2's testing environment, when i run ng test using karmas chrome launcher i get the following error: START: 07 12 2016 11:20:50.590:INFO [karma]: Karma v1.2.0 server started at http://localhost:8888/ 07 12 2016 11:20:50.591:INFO [launcher]: Launching browser Chrome with unlimited concurrency 07 12 2016 11:20:50.682:INFO [launcher]: Starting browser Chrome 07