karma-jasmine

Angular 2 Final Release Router Unit Test

匆匆过客 提交于 2019-11-27 19:41:53
How do I unit test routers in Angular version 2.0.0 with karma and jasmine? Here's what my old unit test looks like in version 2.0.0-beta.14 import { it, inject, injectAsync, beforeEach, beforeEachProviders, TestComponentBuilder } from 'angular2/testing'; import { RootRouter } from 'angular2/src/router/router'; import { Location, RouteParams, Router, RouteRegistry, ROUTER_PRIMARY_COMPONENT } from 'angular2/router'; import { SpyLocation } from 'angular2/src/mock/location_mock'; import { provide } from 'angular2/core'; import { App } from './app'; describe('Router', () => { let location, router;

How do I debug a “[object ErrorEvent] thrown” error in my Karma/Jasmine tests?

旧街凉风 提交于 2019-11-27 17:25:21
I have several failing tests that only output [object ErrorEvent] thrown . I don't see anything in the console that helps me pinpoint the offending code. Is there something I need to do to track these down? [EDIT]: I'm running Karma v1.70, Jasmine v2.7.0 To fix that you have to run your tests without sourcemaps as a workaround: CLI v6.0.8 and above --source-map=false CLI v6.0.x early versions --sourceMap=false CLI v1.x --sourcemaps=false Shortcut ng test -sm=false might also work There is an open issue on that https://github.com/angular/angular-cli/issues/7296 UPDATE : I had that issue as well

Error: You need to include some adapter that implements __karma__.start method

我怕爱的太早我们不能终老 提交于 2019-11-27 13:23:36
I'm trying to add some unit tests to one of my projects. So far I've installed and configured karma, and have installed jasmine. I've one test file in my test/ folder. The karma server has started, the browser page is ready, but karma run fails as follows: $ karma run karma-conf.js [2014-06-14 15:19:11.046] [DEBUG] config - Loading config /foo/test/karma-conf.js Waiting for previous execution... Chrome 35.0.1916 (Linux) ERROR You need to include some adapter that implements __karma__.start method! This error message doesn't Google well. Is this something obvious, or do I need to provide more

Spy on a service method call using jasmine Spies

岁酱吖の 提交于 2019-11-27 12:24:21
问题 I have the following controller ViewMeetingCtrl.js (function () { 'use strict'; angular.module('MyApp').controller('ViewMeetingCtrl', ViewMeetingCtrl); ViewMeetingCtrl.$inject = ['$scope', '$state', '$http', '$translate', 'notificationService', 'meetingService', '$modal', 'meeting', 'attachmentService']; function ViewMeetingCtrl($scope, $state, $http, $translate, notificationService, meetingService, $modal, meeting, attachmentService) { $scope.meeting = meeting; $scope.cancelMeeting =

What is the difference between createspy and createspyobj

房东的猫 提交于 2019-11-27 10:15:44
问题 I have used in my code like. return $provide.decorator('aservice', function($delegate) { $delegate.addFn = jasmine.createSpy().andReturn(true); return $delegate; }); In that what createSpy do? can i change the createSpy calls to createspyobj calls. By using createSpy, we can create one function/method mocks. Createspyobj can do multiple functions mocks. Am i right? What would be the difference. 回答1: jasmine.createSpy can be used when there is no function to spy on. It will track calls and

Unit testing a modalInstance controller with Karma / Jasmine

末鹿安然 提交于 2019-11-27 09:32:34
问题 EDIT : Quick & Dirty solution at the end of this post I am using a modal window from AngularUI-Bootstrap in the same way that it is explained on the website, except that I splitted files. Therefore I have : CallingController.js : $scope.delete = function () { if ($scope.selected.length > 0) { // [...] // preparing data // [...] var modalInstance = $modal.open({ templateUrl: 'views/modalView.html', controller: 'modalCtrl', resolve: { itemArray: function () { return $scope.selected; } } });

Angular tests failing with Failed to execute 'send' on 'XMLHttpRequest'

那年仲夏 提交于 2019-11-27 09:14:44
问题 I am trying to test my angular 4.1.0 component - export class CellComponent implements OnInit { lines: Observable<Array<ILine>>; @Input() dep: string; @Input() embedded: boolean; @Input() dashboard: boolean; constructor( public dataService: CellService, private route: ActivatedRoute, private router: Router, private store: Store<AppStore>) { } } However, a simple "should create" test throws this cryptic error... NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'ng://

Testing - Can't resolve all parameters for (ClassName)

扶醉桌前 提交于 2019-11-27 09:03:43
Context I created an ApiService class to be able to handle our custom API queries, while using our own serializer + other features. ApiService 's constructor signature is: constructor(metaManager: MetaManager, connector: ApiConnectorService, eventDispatcher: EventDispatcher); MetaManager is an injectable service that handles api's metadatas. ApiConnectorService is a service which is wrapping Http to add our custom headers and signature system. EventDispatcher is basically Symfony's event dispatcher system, in typescript. Problem When I test the ApiService , I do an initialization in beforeEach

Jasmine mock chained methods with Karma and Angular

拟墨画扇 提交于 2019-11-27 08:35:03
问题 I want to mock angular.element . And I want to ensure angular.element has been called a certain amount of times and that anguler.element.attr has been called too. I have the following code: var things = $scope.getThings(); for (var i = 0; i < things.length; i++) { if (things[i].type == "xyz") { angular.element("#thing-" + things[i].id) .attr("foo", things[i].bar); }; }; In my test I have: var things = [ { id: 1, type: "xyz", bar: 10 }, { id: 2, type: "abc", bar: 33 } ]; spyOn($rootScope,

Karma/Jasmine times out without running tests

元气小坏坏 提交于 2019-11-27 05:33:38
问题 I'm trying to run Karma/Jasmine from Grunt on a project generated with http://newtriks.com/2013/12/31/automating-react-with-yeoman-and-grunt/ Karma launches PhantomJS (or Chrome) and, depending on singleRun, it either times out or just sits there and does nothing. I've tried changing captureTimeout and browserNoActivityTimeout based on reading solutions from people with similar problems, but it doesn't seem to work. My relevant pacakge versions etc.: NodeJS: 0.10.25 Karma: 0.12.16 Webpack: 1