karma-runner

Karma/Istanbul Code Coverage does not find functions and always returns 100%

被刻印的时光 ゝ 提交于 2019-12-17 19:53:40
问题 I am attempting to add Code Coverage for my Karma tests, however although it finds the correct JS files that I'm testing, it does not find the functions inside those files. From what I have read so far I believe it to be to do with the files not being correctly browserified before being passed to istanbul to do the coverage, but admittedly I am new to this so I'm hoping for some suggestions. Here is my JS file(common.js): var applicationSettings = require('./settings'); var common = {

karma error 'There is no timestamp for'

天大地大妈咪最大 提交于 2019-12-17 17:59:43
问题 Trying to get karma working with requirejs. I don't understand why I am getting all of these errors when running Karma: ERROR: 'There is no timestamp for /base/test/mainSpec.js?bust=1387739317116!' ERROR: 'There is no timestamp for /base/app/main.js?bust=1387739317116!' ERROR: 'There is no timestamp for /base/bower_components/jquery/jquery.js?bust=1387739317116!' When I go to the network tab in inspector, all of the files are there with no 404s. I'm a little confused because karma seems to be

Karma: Running a single test file from command line

[亡魂溺海] 提交于 2019-12-17 17:33:54
问题 So, I've been looking all over for this, found "similar" answers here, but not exactly what I want. Right now if I want to test a single file with karma, I need to do fit() , fdescribe() on the file in question... However, what I do want is to be able to just call karma, with the config file, and direct it to a specific file, so I don't need to modify the file at all, ie: karma run --conf karma.conf.js --file /path/to/specific/test_file.js is it possible to do this? Or with any helper? (using

Detecting Environment When Running Karma

天大地大妈咪最大 提交于 2019-12-17 17:07:22
问题 I have two environments I'm running my tests in (locally, and travic ci). And I need to make a few tweaks in my tests if I'm running them locally. Is it possible to do it using Karma without having two separate configuration files? 回答1: You can programmatically call karma and pass it a configuration object, then listen the callback to close the server: karma.server.start(config, function (exitCode){ if(exitCode){ console.err('Error in somewhere!'); } }); The config object is basically an

Angular error running Karma tests: HTML5 mode requires a <base> tag

被刻印的时光 ゝ 提交于 2019-12-17 16:30:24
问题 I have a single-page Angular app with a Rails backend. I am using a tag in my index.html file, but when I run my front-end unit tests using Karma, I get this: $location in HTML5 mode requires a <base> tag to be present I am doing this in my main .js file: angular.module('my.module').config( function($locationProvider, $routeProvider) { $locationProvider.html5Mode( true ); } So, is there any way I can inject a <base> element in the page that karma actually renders? Or else, tell Angular/Karma

Unit testing AngularJS factories that have dependencies

僤鯓⒐⒋嵵緔 提交于 2019-12-17 15:15:16
问题 When unit testing an Angular factory (with Karma + Jasmine), how do I inject a stub dependency into the factory under test? Here's my factory: mod = angular.module('myFactoryMod', []); mod.factory('myFactory', [ '$log', 'oneOfMyOtherServices', function($log, svc) { return makeSomethingThatDoesSomethingWithTheseDependencies($log, svc); } ]); oneOfMyOtherServices is needed when instantiating my factory. Here's my test: it('can get an instance of my factory', function() { var

How to test nodejs backend code with Karma (testacular)

混江龙づ霸主 提交于 2019-12-17 15:13:23
问题 How do I setup Karma to run my backend unit tests (written with Mocha)? If I add my backend test script to the files = [] , it fails stating that require is undefined. 回答1: You don't. Karma is only for testing browser-based code. If you have a project with mocha tests on the backend and karma/mocha on the front end, try editing your package.json under scripts to set test to: mocha -R spec && karma run karma.con Then, if npm test returns true, you'll know it's safe to commit or deploy. 回答2: It

Angular 1.6.0: “Possibly unhandled rejection” error [duplicate]

北城以北 提交于 2019-12-17 08:55:12
问题 This question already has answers here : Possibly unhandled rejection in Angular 1.6 (9 answers) Closed last year . We have a pattern for resolving promises in our Angular app that has served us well up until Angular 1.6.0: resource.get().$promise .then(function (response) { // do something with the response }, function (error) { // pass the error the the error service return errorService.handleError(error); }); And here is how we are triggering the error in Karma: resourceMock.get = function

Angular 1.6.0: “Possibly unhandled rejection” error [duplicate]

拜拜、爱过 提交于 2019-12-17 08:55:10
问题 This question already has answers here : Possibly unhandled rejection in Angular 1.6 (9 answers) Closed last year . We have a pattern for resolving promises in our Angular app that has served us well up until Angular 1.6.0: resource.get().$promise .then(function (response) { // do something with the response }, function (error) { // pass the error the the error service return errorService.handleError(error); }); And here is how we are triggering the error in Karma: resourceMock.get = function

Can Protractor and Karma be used together?

别来无恙 提交于 2019-12-17 03:52:23
问题 If Protractor is replacing Angular Scenario Runner for E2E testing, does that mean I will still be able to use it with Karma as my E2E testing framework ? 回答1: Not recommended by the current maintainer of Protractor: https://github.com/angular/protractor/issues/9#issuecomment-19927049 Protractor and Karma should not be used together; instead they provide separate systems for running tests. Protractor and Karma cover different aspects of testing - Karma is intended mostly for unit tests, while