karma-jasmine

Is jasmine supposed to execute specs in the order they are declared or in a random order?

余生颓废 提交于 2019-11-29 09:09:45
un-comment the last spec. All hell breaks loose... why? describe('test', function() { var index = 1; it('test 1', function() { expect(index).toBe(1); index++; }); it('test 2', function() { expect(index).toBe(2); index++; }); it('test 3', function() { expect(index).toBe(3); index++; }); it('test 4', function() { expect(index).toBe(4); index++; }); it('test 5', function() { expect(index).toBe(5); index++; }); it('test 6', function() { expect(index).toBe(6); index++; }); it('test 7', function() { expect(index).toBe(7); index++; }); it('test 8', function() { expect(index).toBe(8); index++; }); it(

angular2 testing using jasmine for subscribe method

和自甴很熟 提交于 2019-11-29 06:25:12
问题 I have a spec code to test like this it('login test', () => { const fixture = TestBed.createComponent(component); fixture.detectChanges(); let authService = fixture.debugElement.injector.get(Auth); spyOn(authService, 'login').and.returnValue(''); const elements = fixture.nativeElement; fixture.componentInstance.login(); expect(authService.login).toHaveBeenCalled(); }); and the implementation code like this login() { this.auth.login(this.username, this.password).subscribe(() => { } }); } it

jasmine test fails with undefined is not a function(evaluating $browser.$$checkUrlChange())

天涯浪子 提交于 2019-11-29 05:30:05
问题 I have a following controller: .controller('ProjectUserAddCtrl', ['$scope', 'ProjectUser', '$q', 'i18nNotifications', function($scope, ProjectUser, $q, i18nNotifications) { var buildUnassignedUsers = function(users, project) { var unassignedUsers = []; angular.forEach(users, function(user) { var match; angular.forEach(project.projectUsers, function(projectUser) { if(match) {return;} if(projectUser.user.id === user.id) { match = true; } }); if(!match) { unassignedUsers.push(user); } }); $scope

What is the difference between nativeElement.click() and event handler's click?

拥有回忆 提交于 2019-11-29 03:01:09
问题 I have been trying to perform a test for angular 2 application that clicks a submit button which calls a function. I usually use two methods to perform the same. element.nativeElement.click() and element.triggerEventHandler('click',null); I thought both these methods were same, until I came across this situation where triggering event handler method does not work. element = fixture.debugElement.query(By.css('.dropList li')); element.triggerEventHandler('click',null); //Click event works here

Testing ngOnChanges lifecycle hook in Angular 2

一笑奈何 提交于 2019-11-29 03:00:23
Given the following code I try to test the ngOnChanges lifecycle hook of Angular2: import { it, inject, fdescribe, beforeEachProviders, } from '@angular/core/testing'; import {TestComponentBuilder} from '@angular/compiler/testing'; import {Component, OnChanges, Input} from '@angular/core'; @Component({ selector: 'test', template: `<p>{{value}}</p>`, }) export class TestComponent implements OnChanges { @Input() value: string; ngOnChanges(changes: {}): any { // should be called } } fdescribe('TestComponent', () => { let tcb: TestComponentBuilder; beforeEachProviders(() => [ TestComponentBuilder,

How to change value of a select box in angular2 unit test?

陌路散爱 提交于 2019-11-29 02:48:47
问题 I have an Angular2 component that contains a select box that looks like <select [(ngModel)]="envFilter" class="form-control" name="envSelector" (ngModelChange)="onChangeFilter($event)"> <option *ngFor="let env of envs" [ngValue]="env">{{env}}</option> </select> I am trying to write a unit test for the ngModelChange event. This is my latest failing attempt it("should filter and show correct items", async(() => { fixture.detectChanges(); fixture.whenStable().then(() => { el = fixture

Error: No provider for “framework:jasmine”! (Resolving: framework:jasmine)

﹥>﹥吖頭↗ 提交于 2019-11-29 01:25:47
问题 I have run on my windows console: npm install -g yo grunt-cli bower npm install -g generator-angular yo angular Then I started my project with webstorm and did right click on the karma.conf.js file in the project explorer where I have the menu item 'Run karma.conf.js' and start the karma runner. Then I get his exception: ...\app\node_modules\karma\node_modules\di\lib\injector.js:9 throw error('No provider for "' + name + '"!'); ^ Error: No provider for "framework:jasmine"! (Resolving:

Spy on a service method call using jasmine Spies

别说谁变了你拦得住时间么 提交于 2019-11-28 19:36:36
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 = cancelMeeting; function cancelMeeting(meetingId, companyId) { meetingService.sendCancelNotices(companyId,

Updating the version of Jasmine used in karma-jasmine

ⅰ亾dé卋堺 提交于 2019-11-28 18:48:10
问题 Questions How can I update the version of Jasmine used when running Jasmine via Karma using the karma-jasmine plugin? Will Jasmine only get updated whenever the karma-jasmine plugin integrates a newer version of Jasmine, or can I point the karma-jasmine plugin to a newer version of Jasmine? What version of Jasmine is installed by karma-jasmine? Background I've installed Karma and karma-jasmine using Yeoman as follows: $ npm install -g generator-angular $ mkdir myapp && cd $_ $ yo angular

Unit testing a modalInstance controller with Karma / Jasmine

大兔子大兔子 提交于 2019-11-28 16:06:54
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; } } }); modalInstance.result.then(function (confirm) { if (confirm === true) { // [...] // treat // [...] } }); }