jasmine

Barrel Import Appears To Break Load Order

我与影子孤独终老i 提交于 2019-12-20 02:57:07
问题 I've got a component that I'm trying to unit test but I keep getting these errors, depending on my import statements: Error: Cannot resolve all parameters for 'MyComponent'(undefined, FormBuilder). TypeError: Cannot read property 'toString' of undefined My component takes 2 parameters, one the FormBuilder and one a custom service, that must be injected: import {MyService} from '../'; @Component({ ..., providers: [MyService] }) class MyComponent { constructor(service: MyService, fb:

Angular unit tests TypeError: this.http.get(…).pipe is not a function

一世执手 提交于 2019-12-20 01:58:08
问题 I'm following this example to make a unit test for service (get request coming from spring app backend) https://angular.io/guide/testing#testing-http-services Service class : @Injectable() export class TarifService { constructor(private messageService: MessageService, private http: HttpClient) { } public getTarifs(): Observable<Tarif[]> { return this.http.get<Tarif[]>(tarifffsURL).pipe( tap(() => {}), catchError(this.handleError('getTarifs', [])) ); } } Unit Test describe('TarifService', () =

SpyOn individually exported ES6 functions

久未见 提交于 2019-12-19 17:44:44
问题 tl;dr: I use Jasmine ; I want to test aaa function which called bbb from the same module; I want to spy on bbb , but eventually aaa called the original bbb function, not a spy; How can I force aaa to call the spy? The Module: export function aaa() { return bbb(); } export function bbb() { return 222; } The test: import * as util from 'my-module'; describe('aaa test', () => { let bbbSpy: Spy; beforeEach(() => { bbbSpy = spyOn(util, 'bbb'); }); it('should return SPYED', () => { bbbSpy.and

How to fix beforeEachProviders (deprecated on RC4)

谁说我不能喝 提交于 2019-12-19 14:44:40
问题 Ive just upgraded Angular2 from RC3 to RC4 ... import { expect, it, iit, xit, describe, ddescribe, xdescribe, beforeEach, beforeEachProviders, withProviders, async, inject } from '@angular/core/testing'; In my unit test I have the following code ... beforeEachProviders(() => [ {provide: Router, useClass: MockRouter} ]); This works fine but since moving to RC4 I have a deprecation warning on beforeEachProviders . Anyone know what the new way of doing things is? Or should I import

Jasmine: How to get name of current test

佐手、 提交于 2019-12-19 12:28:51
问题 Is there a way of getting the name of the currently running test? Some (heavily simplified) code may help explain. I want to avoid the duplication of "test1" / "test2" in the calls to performTest : describe("some bogus tests", function () { function performTest(uniqueName, speed) { var result = functionUnderTest(uniqueName, speed); expect(result).toBeTruthy(); } it("test1", function () { performTest("test1", "fast"); }); it("test2", function () { performTest("test2", "slow"); }); }); UPDATE I

Location reload in Jasmine

依然范特西╮ 提交于 2019-12-19 08:29:07
问题 I'm really not sure how to approach testing this? (spyOn?) function reloadPage() { $('#logo').click(function() { location.reload(); }) } Any advice would be great! 回答1: The reason you may be unsure about how to test this piece of code is because it's doing 2 different things and you should break it up into smaller chunks. I see two distinct functions here: click event handling reload page So why not break up the logic like so? function reloadPage() { location.reload(); } function bindEvents()

Download file on Firefox with protractor

二次信任 提交于 2019-12-19 08:01:19
问题 I need to download a zip file on Firefox with protractor. On clicking on download link, Windows dialog asking to Open/Save the file pops up. So How can I handle that. What args do I need to pass to driver? With chrome I can do that with download: { 'prompt_for_download': false }, but what should i do with firefox. 回答1: The problem is - you cannot manipulate that "Save As..." dialog via protractor/selenium . You should avoid it being opened in the first place and let firefox automatically

Get error when try to use jasmine and angular

折月煮酒 提交于 2019-12-19 05:44:50
问题 When I try to use $httpBackend.flush(); I get error TypeError: $browser.cookies is not a function. I can't find any information about this kind of error and any solutions. describe("someText", function() { var $httpBackend; var someManager; var authRequestHandler; var dataMockup = []; beforeEach(function(){ module('app'); inject(function($injector){ $httpBackend = $injector.get('$httpBackend'); someManager = $injector.get('someManager'); authRequestHandler = $httpBackend.when('GET', 'someUrl

Jasmine 2.0 SpecRunner vs Karma

耗尽温柔 提交于 2019-12-19 05:11:49
问题 I just started using Jasmine and I was able to use the SpecRunner from the Html just fine. However when I configured Karma I encountered a discrepancy: describe('Calculator', function(){ var obj; beforeEach(function(){ //initialize object obj = new Object(); this.addMatchers({ toBeFive: function () { return { compare: function (actual, expected) { return { pass: actual === 5, message: actual + ' is not exactly 5' } } }; }, This piece of code does not work from the SpecRunner.html: this

What is the difference between testbed.get and inject in Angular 2/Jasmine testing?

南笙酒味 提交于 2019-12-19 05:04:25
问题 I am new to Angular 2 testing. I am trying to figure out what is the difference in using testsbed.get() and just using inject at the test level. eg: beforeEach(() => { TestBed.configureTestingModule({ providers: [SomeService] }); const testbed = getTestBed(); someService= testbed.get(SomeService); }); }); vs it('test service', inject([SomeService], (someService: SomeService) => { 回答1: inject helper function was historically used since AngularJS as an alternative to direct injector calls. In