karma-jasmine

angular2 testing using jasmine for subscribe method

丶灬走出姿态 提交于 2019-11-30 08:34:56
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 gives error: this.auth.login(...).subscribe is not a function Why does this error happen? You need to

Can webpack 4 modules be configured as to allow Jasmine to spy on their members?

穿精又带淫゛_ 提交于 2019-11-30 07:25:37
问题 I've been unable to get my test jasmine test suite running with webpack 4. After upgrading webpack, I get the following error for almost every test: Error: <spyOn> : getField is not declared writable or has no setter This is due to a common pattern we use to create spys for simple functions is: import * as mod from 'my/module'; //... const funcSpy = spyOn(mod, 'myFunc'); I've played around with module.rules[].type but none of the options seem to do the trick. This webpack GH issue indicates

Angular 4 Error: No provider for ChildrenOutletContexts in Karma-Jasmine Test

末鹿安然 提交于 2019-11-30 06:43:27
My Angular application is working properly, but I am keep getting Karma error when I run ng test command. I have attached app component, spec, module and html along with package.json file. Error looks like this: Failed: No provider for ChildrenOutletContexts! Error: No provider for ChildrenOutletContexts! at injectionError (http://localhost:9876/_karma_webpack_/vendor.bundle.js:39523:90) at noProviderError (http://localhost:9876/_karma_webpack_/vendor.bundle.js:39561:12) at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_._throwOrNull (http://localhost

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

随声附和 提交于 2019-11-30 05:55:24
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.unassignedUsers = unassignedUsers; }; $q.all([ $scope.users, $scope.project ]).then(function(result) {

Angular 2 Jasmine How to test a function of a component

半城伤御伤魂 提交于 2019-11-30 05:14:28
问题 How do I mock the click event of a function in Angular 2? For my Home Component I have: Home Component import { Component } from '@angular/core'; import { Router } from '@angular/router'; @Component({ moduleId: module.id, templateUrl: 'home.component.html', styleUrls: ['home.component.css'], selector: 'home', }) export class HomeComponent { constructor(private router: Router) { } redirectToUpload() { this.router.navigate(['/upload']); } redirectToAbout() { this.router.navigate(['/about']); }

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

雨燕双飞 提交于 2019-11-30 04:10:12
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: framework:jasmine) Then in the console I read I can also use --force so I tried it: grunt --force It took some

Angular testing how to prevent ngOnInit call to test a method directly

五迷三道 提交于 2019-11-30 03:45:30
Context I have a component. Inside of it, the ngOnInit function calls another function of component to retrieve user List. I want to make two series of tets: First test the ngOnInit is triggered properly and populate the user list In a second time I want to test my refresh function which also call getUserList() The first test, with ngOnInit trigger, when I call fixture.detectChanges() works properly. Problem My problem is when testing the refresh function: as soon as I call fixture.detectChanges(), ngOnInit is triggered and then I am unable to know where my results come from and if my refresh(

MatDialog Service Unit Test Angular 6 Error

我们两清 提交于 2019-11-30 03:18:24
问题 I'm having modal service to open, confirm and close dialog and i am making its unit test file but i got and error on Angular and this is the code. modal.service.ts @Injectable() export class ModalService { constructor(private dialog: MatDialog) { } public open<modalType>(modalComponent: ComponentType<modalType>): Observable<any> { let dialogRef: MatDialogRef<any>; dialogRef = this.dialog.open(modalComponent, { maxWidth: '100vw' }); console.log(dialogRef) dialogRef.componentInstance.body =

Karma error - No captured browser, open http://localhost:9876/

百般思念 提交于 2019-11-30 03:02:51
问题 I just started to use Karma for first time...Following this tutuorial : https://angular.io/docs/ts/latest/guide/testing.html I am writing simple test to check if the title is correct. I always get this error : "No captured browser, open http://localhost:9876/" .I am using Angular 2 and typescript. These are the versions "@angular/core": "2.4.10" "jasmine-core": "^2.6.2", "karma": "^1.7.0". My folder structure looks like this mydashboard -src -app -welcome -welcome.component.ts -welcome

How to get Jasmine's spyOnProperty to work?

三世轮回 提交于 2019-11-30 01:31:54
问题 I saw this post post and was excited to try it out, but I'm unable to get it working. Trying to keep this simple just to figure out what's wrong, but even this is failing. export class SomeService { ... private _myValue: Boolean = false; get myValue(): Boolean { return this._myValue; } set myValue(helper: Boolean) { this._myValue = helper; } And in my unit test, I have: it('should ', inject([SomeService], (someService: SomeService) => { let oldValue = someService.myValue; expect(oldValue)