karma-runner

Karma Start Fails - HeadlessChrome - ERROR Uncaught [object Object]

落花浮王杯 提交于 2019-12-18 15:07:14
问题 I am using Karma to run test on my Angular 4 app. It works locally but when it runs on my host environment (Travis CI) it fails with the following information: INFO [HeadlessChrome 0.0.0 (Ubuntu 0.0.0)]: Connected on socket vT0QnQaqRkn010dfsw with id 10189531 HeadlessChrome 0.0.0 (Ubuntu 0.0.0): Executed 0 of 180 SUCCESS (0 secs / 0 secs) e 0.0.0 (Ubuntu 0.0.0): Executed 1 of 180 SUCCESS (0 secs / 0.714 secs) HeadlessChrome 0.0.0 (Ubuntu 0.0.0) ERROR Uncaught [object Object] at http:/

How to setup Karma runner code coverage?

爱⌒轻易说出口 提交于 2019-12-18 13:59:29
问题 I am attempting to get Karma runner to generate cobertura formatted code coverage reports during a Jenkins build. I can get it to generate a coverage.xml file, but it does not actually have any coverage data. It appears (using LOG_DEBUG ) that the coverage preprocessor is not running. The relevant pieces from my karma.conf.js file are: files = [ JASMINE, JASMINE_ADAPTER, 'app/components/angular/angular.js', 'app/components/angular-mocks/angular-mocks.js', 'tmp/scripts/**/*.js', 'tmp/spec/**/*

mock $httpBackend in angular e2e tests

依然范特西╮ 提交于 2019-12-18 12:30:02
问题 Does anyone have an idea how to mock $httpBackend in angular e2e tests? The idea is stubbing XHR requests while running tests on travis-ci. I'm using karma to proxy assets and partials from my rails app running on travis. I want to do acceptance testing without real DB queries. Here is part of my karma config file: ... files = [ MOCHA, MOCHA_ADAPTER, 'spec/javascripts/support/angular-scenario.js', ANGULAR_SCENARIO_ADAPTER, 'spec/javascripts/support/angular-mocks.js', 'spec/javascripts/e2e/**/

testing angularjs ui-router go() method

倖福魔咒の 提交于 2019-12-18 11:39:10
问题 I have a controller which gets a value from $scope and sends it to a different state: controllers.controller('SearchController', ['$scope', '$state', '$stateParams', function($scope, $state, $stateParams) { $scope.search = function() { $stateParams.query = $scope.keyword; $state.go('search', $stateParams); }; }]); I am unsure how to go about unit testing this search method. How can I either verify that the go method has been called or do some sort of when($state.go('search', $stateParams))

Issue running karma task from gulp

允我心安 提交于 2019-12-18 10:58:34
问题 I am trying to run karma tests from gulp task and I am getting this error: Error: 1 at formatError (C:\Users\Tim\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:161:10) at Gulp.<anonymous> (C:\Users\Tim\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:187:15) at Gulp.emit (events.js:95:17) at Gulp.Orchestrator._emitTaskDone (C:\path\to\project\node_modules\gulp\node_modules\orchestrator\index.js:264:8) at C:\path\to\project\node_modules\gulp\node_modules\orchestrator\index.js:275:23 at

debug in browser using testacular (now karma)

淺唱寂寞╮ 提交于 2019-12-18 10:15:17
问题 I am trying to figure out the best way to debug my unit tests when I break them. Typically in previous test environments I could just run the tests in the browser and breakpoint the test, or the code and see why my test was failing. I can't seem to figure out how to do that with testacular. Is there an easy way to debug unit tests? 回答1: Include "browsers = ['Chrome'];" in your karma.config file. When Chrome opens, you should see "Karma - connected" at the top, with a "Debug" button to the

ReferenceError: Can't find variable: Map

被刻印的时光 ゝ 提交于 2019-12-18 08:31:17
问题 I'm using Angular 4, Webpack 2.4.1, Karma 1.6 and Jasmine 2.6.1 and am writing ES2015 not TypeScript I've got a tiny angular demo app and I want to add unit tests. The demo app itself itself is working and Webpack is bundling everything correctly, but when I try to run the unit tests I see some errors in the console like this: ReferenceError: Can't find variable: Map at Static/js/app.welcome.js:2569 ( app.welcome.js is the name of my component) Webpack appears to be building my test bundle

How to load external Json file using karma+Jasmine for angularJS testing?/

故事扮演 提交于 2019-12-18 04:52:47
问题 Can anyone provide me an example in PLUNKER that how to load JSON file for karma/jasmine test.I want to read the data from JSON file for the test cases i am writing.I have been searching but nowhere they mentioned clear example on how to do it? I appreciate it if anyone can provide with the example. 回答1: You can load an external json data file using require var data = require('./data.json'); console.log(data); // Your test cases goes here and you can use data object 回答2: Set the path to find

Global variables in Karma test runner

大兔子大兔子 提交于 2019-12-17 22:43:58
问题 I have a global variable defined in my main template, which I use to store information bits from the back end, such as the environment context path. I can't move that variable inside a service. How can I expose that variable to Karma when I run the unit tests? 回答1: You either declare that global variable within your test file: var global = "something"; describe('Your test suit', function() { ... }); or add a Javascript file where it's defined to your karma.conf.js file: // list of files /

How can we test non-scope angular controller methods?

若如初见. 提交于 2019-12-17 22:40:13
问题 We have few methods in Angular Controller, which are not on the scope variable. Does anyone know, how we can execute or call those methods inside Jasmine tests? Here is the main code. var testController = TestModule.controller('testController', function($scope, testService) { function handleSuccessOfAPI(data) { if (angular.isObject(data)) { $scope.testData = data; } } function handleFailureOfAPI(status) { console.log("handleFailureOfAPIexecuted :: status :: "+status); } // this is controller