karma-runner

CSS issue testing AngularJS directives with Karma + Jasmine

岁酱吖の 提交于 2019-12-22 04:04:35
问题 I'm using Karma + Jasmine to test my AngularJS directives, I wrote more than 300 tests and I was very happy... until I found an issue that taken me here because I'm stuck: some tests are failing because they need a CSS applied to some elements (a piece of code in my directive does a size computation based on this style), and despite I added the file containing the CSS implementation, this file seems ignored during tests. In my karma config I added the css file in this way: files: [ // ..

Getting grunt karma to run one unit test

谁都会走 提交于 2019-12-22 03:24:49
问题 I was wondering if anyone has got grunt karma to run just one spec that is changed on watch. This is my config below. The problem is that the line grunt.config('karma.unit.options.files', filepath); doesn't seem to be doing anything as all the specs still get run however foo does get output before the karma:unit:run gets fired. grunt.initConfig({ karma: { unit: { configFile: 'karma.conf.js', background: true, singleRun: false, options: { files: allFilesArray } } }, watch: { options: { spawn:

Angular2, testing and resolved data: how to test ngOnINit?

有些话、适合烂在心里 提交于 2019-12-22 02:51:10
问题 I'm working through the Angular2 testing guide and wish to write a test for the ngOnInit() function. The one from the Routing part of the programming guide has this format: let org: Org = null; ngOnInit(): void { let that = this; this.route.data .subscribe((data: { org: Org }) => { that.org = data.org; }); } This is fulfilled through a resolver, like: resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Org> { let id = this.authService.user.orgId; return this

How can I mock an Observable.throw in an Angular2 test?

泪湿孤枕 提交于 2019-12-22 01:55:17
问题 I want to test the error handling in my Angular2 component and therefore want to mock a service to return an Observable.throw('error'). How can that be done using Jasmine and Karma and Angular 2? 回答1: You should create an observable, and just call the observer error . For example let mockService = { error: false, data: 'something', getData: () => { return Observable.create(observer => { if (this.error) { observer.error(new Error(..)) } else { observer.next(this.data); } observer.complete(); }

How to unit test $location service search() method, in AngularJS?

[亡魂溺海] 提交于 2019-12-21 22:11:19
问题 How to create a unit test of AngularJS $location service search() method? I am using Jasmine+Karma for the test and AngularJS 1.3, and unit test is new to me :) This is my service, which is working fine in production btw: 'use strict'; (function () { angular.module('myApp') .service('myService', function ($location) { var _customerId = $location.search().id; /*jshint validthis:true */ this.customerId = _customerId; }); })() And this is my serviceSpec: describe('Service: mySerivce', function()

PhantomJS not captured when ran via build server

六月ゝ 毕业季﹏ 提交于 2019-12-21 04:48:27
问题 I am using Karma and PhantomJS with Jasmine to test my AngularJS. When I run my gulp test locally it works fine, launches PhantomJS and runs all my tests, but when the tests get run on the build server it fails with the following errors: Note that I am using VSTS and using their built in cloud build system (hosted agent). Having said that its pretty much a task runner and I only use it to run gulp tasks (build, test etc) on checkin [32m13 07 2016 15:21:32.260:INFO [karma]: [39mKarma v1.1.1

Angular.js unitest a Directive with external template using html2js - Fail to load templates

为君一笑 提交于 2019-12-21 04:25:21
问题 I am trying to test a Directive which uses external template. I tried all the following solutions with no luck: ng-directive-testing How to test directives that use templateUrl and controllers? AngularJS + Karma + Ng-html2js => Failed to instantiate module ...html I created a test directive (a simple div) and tested it using an inline 'template' and external 'templateUrl'. The inline solution works while the external doesn't: angular.module('AdUnit').directive('actionButton',function(

Take screenshot from Karma while running tests in PhantomJS 2?

时光毁灭记忆、已成空白 提交于 2019-12-21 04:19:15
问题 I need a way to take a screenshot during a test which uses QUnit and Karma to run inside PhantomJS 2.0.1 I've found this command: window.top.callPhantom('render'); That doesn't throw any error but doesn't seem to work, or at least, I don't know where to look for the taken screenshot. Any clue? 回答1: Found a way! Solution I had to edit my custom PhantomJS custom launcher adding an option: PhantomJSCustom: { base: 'PhantomJS', options: { onCallback: function(data){ if (data.type === "render") {

Cannot install phantomJS in Karma

女生的网名这么多〃 提交于 2019-12-21 03:11:37
问题 WARN [config]: config.configure() is deprecated, please use config.set() instead. WARN [plugin]: Cannot find plugin "karma-phantomjs". Did you forget to install it ? npm install karma-phantomjs --save-dev INFO [karma]: Karma v0.10.2 server started at http://localhost:9018/ WARN [launcher]: Can not load "PhantomJS", it is not registered! Perhaps you are missing some plugin? Getting this error. When running npm install karma-phantomjs --save-dev I get an error. npm ERR! 404 'karma-phantomjs' is

How to test directives that use templateUrl and controllers?

左心房为你撑大大i 提交于 2019-12-21 02:22:53
问题 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