jasmine

How can I use a fake/mock/stub child component when testing a component that has ViewChildren in Angular 10+?

馋奶兔 提交于 2021-02-10 14:32:23
问题 Before marking this as a duplicate of this question please note that I'm asking specifically about Angular 10+, because the answers to that question no longer work as of Angular 10. Background I've created a simple example app that helps illustrates my question. The idea with this app is that several "people" will say "hello", and you can respond to any or all of them by typing their name. It looks like this: (Note that the 'hello' from Sue has been greyed out because I responded by typing

I'm getting this error when ran ng e2e: Could not find update-config.json

孤街浪徒 提交于 2021-02-10 14:31:14
问题 Currently I have Protractor v.5.4.2, Node.js v.10.15.39 [09:21:29] I/launcher - Running 1 instances of WebDriver [09:21:29] I/direct - Using ChromeDriver directly... [09:21:29] E/direct - Error code: 135 [09:21:29] E/direct - Error message: Could not find update-config.json. Run 'webdriver-manager update' to download binaries.driver-manager update' to download binaries. anager update' to download binaries. [09:21:29] E/direct - Error: Could not find update-config.json. Run 'webdriver-mes

how to test firestore methods

痴心易碎 提交于 2021-02-07 23:38:10
问题 I have the following issue: I want to test the following methods who make use of Firestore: databaseService.ts import {Injectable} from '@angular/core'; import {AngularFirestore} from '@angular/fire/firestore'; @Injectable({ providedIn: 'root' }) export class DatabaseService { constructor(private afs: AngularFirestore) { } pushToDatabase(subject: string, key: string, object: Object): void { this.afs.collection(subject).doc(key).set(JSON.parse(JSON.stringify(object))); } async getData(subject:

Mock 'window' object in Jasmine + Angular

▼魔方 西西 提交于 2021-02-07 13:16:38
问题 I have a function which I want to unit-test and into it I am comparing global objects window & parent as const isEqual = (window === parent) ; Which is the best way how to mock those objects in Angular/TypeScript? One more idea is to get those objects through function parameters, but anyway it's not solving this problem because I need to mock global window object too if I am using getSomeData(win: Window, parent: Window) { // ... } 回答1: I went with this solution: Create service which will

Mock 'window' object in Jasmine + Angular

安稳与你 提交于 2021-02-07 13:15:54
问题 I have a function which I want to unit-test and into it I am comparing global objects window & parent as const isEqual = (window === parent) ; Which is the best way how to mock those objects in Angular/TypeScript? One more idea is to get those objects through function parameters, but anyway it's not solving this problem because I need to mock global window object too if I am using getSomeData(win: Window, parent: Window) { // ... } 回答1: I went with this solution: Create service which will

How to test multiple sequential calls with Jasmine

时光毁灭记忆、已成空白 提交于 2021-02-07 12:56:39
问题 I am trying to test a function that unsubscribes from all subscriptions: ngOnDestroy() { this.tryUnsubscribe(this.carsSubscription); this.tryUnsubscribe(this.partsSubscription); this.tryUnsubscribe(this.shopsSubscription); } This is the test I wrote for the function: it('should unsubscribe from subscriptions ', () => { spyOn(component, "tryUnsubscribe"); component.ngOnDestroy(); expect(component.tryUnsubscribe).toHaveBeenCalledWith(component['carsSubscription']); expect(component

How do I spyOn Typescript getters and setters?

孤街醉人 提交于 2021-02-07 11:38:13
问题 When I unit test my getters are setters for Typescript, I cannot find a way to spy on those getters and setters. Instead, the object immediately gets evaluated. I am using Jasmine to unit test. 回答1: It is not supported yet, but there is a Jasmine issue for supporting getters. If you really need the support now, you can extend SpyRegistry.js file and add the code that apsillers proposed: this.spyOnProperty = function(obj, methodName, accessType) { ... var desc = Object.getPropertyDescriptor

import * as (jasmine spyOn) not writable

你。 提交于 2021-02-07 11:23:04
问题 After upgrading to babel 7.1.5 my tests fail when i'm using import * as. test.spec.js import * as Helper from "../../../../src/renderer/modules/Helper"; describe('Testing', () => { it('Should import correctly', () => { console.log(Helper.test()) // a spyOn(Helper, 'test').and.returnValue('b'); }); }); Helper.js function test() { return 'a' } export {test} ERROR 'Upgrade.spec.js (7:8)', 'a' Error: <spyOn> : test is not declared writable or has no setter Usage: spyOn(<object>, <methodName>) at

import * as (jasmine spyOn) not writable

て烟熏妆下的殇ゞ 提交于 2021-02-07 11:22:34
问题 After upgrading to babel 7.1.5 my tests fail when i'm using import * as. test.spec.js import * as Helper from "../../../../src/renderer/modules/Helper"; describe('Testing', () => { it('Should import correctly', () => { console.log(Helper.test()) // a spyOn(Helper, 'test').and.returnValue('b'); }); }); Helper.js function test() { return 'a' } export {test} ERROR 'Upgrade.spec.js (7:8)', 'a' Error: <spyOn> : test is not declared writable or has no setter Usage: spyOn(<object>, <methodName>) at

Testing Cloud Functions for Firebase with Jasmine and Typescript

佐手、 提交于 2021-02-07 11:01:29
问题 I'm currently investigating Google Cloud Functions and have some basic test functions written in typescript. The functions work as expected and I am now attempting to create unit tests using Jasmine. (I'm not using Chai/sinon as per the docs as the rest of my project uses jasmine). I have two issues 1) the test does not run due to this error throw new Error('Firebase config variables are not available. ' + ^ Error: Firebase config variables are not available. Please use the latest version of