karma-runner

WebStorm - Jasmine jQuery

大兔子大兔子 提交于 2019-12-24 14:08:23
问题 I'm quite new to the usage of WebStorm, but it's not working as epected. I had a project in the past, but now I try to recreate it and try to unit test my code. I'm very new to unit testing JavaScript code. So, I have a file karma.conf.js which contains the following: module.exports = function(config){ config.set({ basePath : './', files : [ '../../Resources/External/Bower/angular/angular.js', '../../Resources/External/Bower/angular-mocks/angular-mocks.js', '../../Resources/Scripts/OfficeUI

Tracing errors using karma + babel + webpack with bundles

牧云@^-^@ 提交于 2019-12-24 13:05:46
问题 Using karma + babel + webpack to run ES6 unit tests. I use a webpack bundle to locate and transpile the ES6. It all works, but whenever there is an error in any test file I get messages with no indication where the error originated, like Uncaught TypeError: Cannot read property 'querySelector' of null at /pth/to/test.bundle.js:13256 It's always /pth/to/test.bundle.js:xxxx . Any idea how to make it show more useful messages? Here's my config module.exports = function(config) { config.set({

How to test an angular app with class inheritance?

 ̄綄美尐妖づ 提交于 2019-12-24 12:23:52
问题 I can test normal controllers fine. I cannot test controllers that inherit a base controller. This is how we've been defining subclassed-controllers: app.NavController = app.BaseController.extend({ ... }); This is the base: app.BaseController = Class.extend({ $scope: null, init: function($scope) { this.$scope = $scope; this.defineListeners(); this.defineScope(); }, defineListeners: function() { // this.$scope.$on('$destroy',this.destroy.bind(this)); }, ... }); app.controller('BaseController',

Testing directive that uses bootstrap popover

回眸只為那壹抹淺笑 提交于 2019-12-24 10:35:05
问题 I have directive that uses bootstrap's popover. It becomes popover when variable is set: if (newValue.show === true) { element.popover('show'); } How can I make spy test with karma/jasmine tests? I tried this: spyOn(element, 'popover'); it('should call bootstrap method popover', function () { $scope.$apply(function() { $scope.value.show = true; }); expect(element.popover).toHaveBeenCalled() }); But I get error: Expected spy popover to have been called. Error: Expected spy popover to have been

How to clean cache before $httpBackend.flush() in AngularJs Unit Test?

独自空忆成欢 提交于 2019-12-24 09:44:07
问题 I need to make unit test for a directive in my Angular project. This directive refer a service which use $http required get data and then store them in local cache. and my test case like this: describe('nationality testing',function(){ it('should get countries',function(){ var mockCountries=[{"CountryID":1,"Name":"Afghanistan","Nationality":"Afghan"},{"CountryID":2,"Name":"South Africa","Nationality":"South African"},{"CountryID":3,"Name":"Albania","Nationality":"Albanian"},{"CountryID":4,

AsyncTestCompleter Browserify Angular2 HTTP Mock Test

痞子三分冷 提交于 2019-12-24 09:30:44
问题 I am about to get started with Angular 2 tests, I am pretty new to Angular 2 and got stuck with testing. I am following the testing guide: https://angular.io/docs/ts/latest/guide/testing.html > TimesheetCrusher@0.0.5 test C:\Users\Toby\WebstormProjects\timesheetCrusher > tsc && concurrently "tsc -w" "karma start karma.conf.js" [1] 10 10 2016 09:11:27.801:DEBUG [plugin]: Loading inlined plugin (defining framework:jasmine). [1] 10 10 2016 09:11:27.807:DEBUG [plugin]: Loading inlined plugin

Karma unknown provider error

妖精的绣舞 提交于 2019-12-24 09:29:33
问题 I'm a total noob to unit testing javaScript, angularJS, and Karma. I've been able to write passing tests for the controllers, but now that I'm attempting to test the services, I'm getting the following error: Unknown provider <- nProvider <- User where User is the name of my service and from what I can tell, "n" is the $http dependency for that service (minified). Here is my UserService (TypeScript): /// <reference path="../../lib/angular/angular.d.ts" /> module MyApp.Services{ export class

Jasmine Karma Error “An error was thrown in afterAll\nUncaught ReferenceError: container is not defined thrown”

江枫思渺然 提交于 2019-12-24 08:37:22
问题 I keep getting an error when running jasmine tests via karma test runner, which reads like this: { "message": "An error was thrown in afterAll\nUncaught ReferenceError: container is not defined thrown", "str": "An error was thrown in afterAll\nUncaught ReferenceError: container is not defined thrown" } My package.json is as follows: { "name": "3dm", "version": "1.0.0", "description": "3dm", "main": "src/index.html", "dependencies": { "three-obj-loader": "^1.1.3", "three.js": "*" },

How can I 'force' ALL karma test to fail if an eslint error is found?

非 Y 不嫁゛ 提交于 2019-12-24 08:29:48
问题 I have found that sometimes people do not realise they have linting errors in their tests when they run them since they are show before the test progress/information. Is there any configuration which will cause ALL tests to fail if any of the tests have any linting errors? I am using mocha with karma. Thanks. 回答1: Make the ESLint execution a part of the grunt or gulp or "npm" task (whichever you use). For instance, when we run grunt test , first the ESLint is executed and then karma . If

testing JSONP $resource AngularJS

北城以北 提交于 2019-12-24 06:57:05
问题 How do I test a request being sent and data is being received with a JSONP service? angular.module('search', []) .factory('SearchService', function($q,$rootScope,$resource) { var _search = {}; _search.user = function(opts){ return $resource('https://api.github.com/users/:user', {user: opts.user}, { search: {method:'JSONP',params:{callback: 'JSON_CALLBACK'}} }); } return _search; }); Following the GET request examples: describe('search tests', function () { var svc, httpBackend; beforeEach