jasmine

How to write test cases for Subscriber and timeout inside ngOnit method?

一个人想着一个人 提交于 2020-12-27 06:14:43
问题 I have a class in angular8 application with following ngOnit method ngOnInit(): void { this.setCustomizedValues(); this.sub = PubSub.subscribe('highlightEntity', (subId, entityIdentifier: string) => { document.querySelector(entityIdentifier).classList.add('highlight'); setTimeout(() => { document.querySelector(entityIdentifier).classList.remove('highlight'); }, 2000); }); } I have initialised the following test case describe('aComponent', () => { let httpCallerServiceStub = jasmine

Do you need spies to test if a function has been called in Jasmine?

我是研究僧i 提交于 2020-12-13 03:02:23
问题 Am learning Jasmine, wondering if the following test would be valid? And if not, can someone explain why? I've been reading a number of tutorials and can't find a good explanation that has helped me understand why I can't seem to write a test like the one below correctly. // spec describe("when cart is clicked", function() { it("should call the populateNotes function", function() { $("#show-cart").click() expect(populateNotes()).toHaveBeenCalled(); }) }) // code $("#show-cart").click(function

Jasmine Angular 9 test failing because 'unreachable' stack trace at injectableDefOrInjectorDefFactory

牧云@^-^@ 提交于 2020-12-08 06:47:06
问题 I created an Angular application under 4. I have migrated from version to version and am currently latest version 9. I was reviewing my tests. I have a Login component that I had 3 working tests and now all are failing. It is now returning the following: LoginComponent should be created ... Failed: unreachable Error: unreachable at injectableDefOrInjectorDefFactory (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:17302:1) at providerToFactory

Angular 2 and Jasmine unit testing: cannot get the innerHtml

陌路散爱 提交于 2020-12-08 06:20:23
问题 I am using one of the examples that test a component 'WelcomeComponent': import { Component, OnInit } from '@angular/core'; import { UserService } from './model/user.service'; @Component({ selector: 'app-welcome', template: '<h3>{{welcome}}</h3>' }) export class WelcomeComponent implements OnInit { welcome = '-- not initialized yet --'; constructor(private userService: UserService) { } ngOnInit(): void { this.welcome = this.userService.isLoggedIn ? 'Welcome ' + this.userService.user.name :

Angular 2 and Jasmine unit testing: cannot get the innerHtml

泄露秘密 提交于 2020-12-08 06:20:01
问题 I am using one of the examples that test a component 'WelcomeComponent': import { Component, OnInit } from '@angular/core'; import { UserService } from './model/user.service'; @Component({ selector: 'app-welcome', template: '<h3>{{welcome}}</h3>' }) export class WelcomeComponent implements OnInit { welcome = '-- not initialized yet --'; constructor(private userService: UserService) { } ngOnInit(): void { this.welcome = this.userService.isLoggedIn ? 'Welcome ' + this.userService.user.name :