jasmine

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

回眸只為那壹抹淺笑 提交于 2019-12-02 01:43:34
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', () => { let tarifService: TarifService; let httpClientSpy: { get: jasmine.Spy }; let expectedTarifs;

I am finding trouble using log4js-protractor-appender

我只是一个虾纸丫 提交于 2019-12-02 01:15:33
问题 My log4js.js file code 'use strict'; var log4js = require('log4js'); var log4jsGen = { getLogger: function getLogger() { log4js.loadAppender('file'); log4js.addAppender(log4js.appenders.file('./ApplicationLogs.log'), 'logs'); var logger = log4js.getLogger('logs'); return logger; } }; module.exports = log4jsGen; My conf.js file(specific to appender section only) "appenders": [{ "type": "log4js-protractor-appender", "append": 'false', "maxLogSize": 20480, "backups": 3, "category": "relative

Angularjs testing (Jasmine) - $http returning 'No pending request to flush'

怎甘沉沦 提交于 2019-12-01 23:57:30
My UserManager service automatically fires a $http POST every hour to refresh the user access token. I'm trying to mock that call to verify that the token is being refreshed, but when I try to flush the $httpbackend I get an error saying 'No pending requests to flush' even though I know that the refresh function has been called (added a console.log just to verify). Either the fact that the function is being called through a setTimeOut is effecting the $httpbackend or I'm missing something else. Code attached bellow: describe("UserManager Service Testing", function() { beforeEach(angular.mock

unit testing typescript directive template karma-jasmine, html is not defined

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 23:50:41
Recently i started unit testing on my typescript code using karma-jasmine. After creating and running test case for a service and a simple directive, i created one test case for custom directive which has one controller(which is injecting one service) and is using 4 scope variable for communicating with outside world. It's a simple unit test case to check whether directive is rendering its template or not. While running this unit test case, karma throws some error 09 03 2016 19:59:27.056:INFO [framework.browserify]: bundle built 09 03 2016 19:59:27.063:INFO [karma]: Karma v0.13.21 server

Failing unit test of factory with dependency in AngularJS using Jasmine & Karma

穿精又带淫゛_ 提交于 2019-12-01 21:05:22
I am using Jasmine to test an AngularJS factory. I am having difficulty testing a factory that has a dependency. I have included the code for the factory I am testing and the test code. The problem is that I am getting errors and the test is failing. This is the error I am seeing: Chrome 33.0.1750 (Mac OS X 10.8.5) Testing my Test Service can get an instance of my factory FAILED Error: [$injector:unpr] http://errors.angularjs.org/1.2.8/$injector/unpr?p0=TestThisServiceProvider%20%3C-%20TestThisService at Error (native) at /Users/.../www/lib/angular/angular.min.js:6:449 at /Users/.../www/lib

Protractor clicking through an array of elements

别来无恙 提交于 2019-12-01 20:05:30
I'm quite new to e2e testing and in using protractor / jasmine framework. I know how to get an array of elements and also how to click on an anchor. But how would / is it even possible to click through a list of anchors returned by a element selector / repeater? I've been trying various ways, but as an example (latest one which hasn't been deleted lol) this is what I got: element.all(by.repeater('link in links')).then(function(links) { links.forEach(function(link) { link.click().then(function() { console.log('callback for click '); }); }); }); This appears to take the first element and click

Angular & Jasmine Unit Test change event for input[type=“file”]

◇◆丶佛笑我妖孽 提交于 2019-12-01 19:53:28
I am trying to go for 100% test coverage, but i can't seem to test the stuff inside this onUploadFile function. ```html template <input type="file" formControlName="theUpload" id="upload" (change)="onUploadFile($event, i, true)"> ```filing.ts file onUploadFile(evt: Event, index: number, isReq: boolean = false): void { const reader = new FileReader(); const target = <HTMLInputElement>evt.target; if (target.files && target.files.length) { const file = target.files[0]; reader.readAsDataURL(file); reader.onload = () => { this.getUploadFormGroup(index, isReq).patchValue({ filename: file.name,

Unit testing with Webpack, Jasmine (-core), typescript

蹲街弑〆低调 提交于 2019-12-01 18:49:56
I have a project that is using webpack to bundle all code into a single file. The project is using Typescript and it is working fine at the moment. I've gone to add unit testing and jasmine seems to be the way (one of the many ways) forward. Its actually jasmine-core that is included in the package.json - not sure how much of a difference that makes. So running a very simple test such as it('true is true', function(){ expect(true).toEqual(true); }); works fine. But when I add tests that require the use of an import - eg import MyService = require('./MyServices'); then when I run the tests it

Protractor clicking through an array of elements

亡梦爱人 提交于 2019-12-01 18:43:07
问题 I'm quite new to e2e testing and in using protractor / jasmine framework. I know how to get an array of elements and also how to click on an anchor. But how would / is it even possible to click through a list of anchors returned by a element selector / repeater? I've been trying various ways, but as an example (latest one which hasn't been deleted lol) this is what I got: element.all(by.repeater('link in links')).then(function(links) { links.forEach(function(link) { link.click().then(function

Jasmine SpyOn same method more than once

孤者浪人 提交于 2019-12-01 17:51:31
问题 I have an angular controller with a method that calls $location.search() twice. First time is just $location.search() to return the value. Second time is $location.search("foo", null) to clear it. I have the following spy in my unit test: spyOn($location, "search").and.returnValue({ foo: "bar" }); It appears the spy returns {foo:"bar"} even when my implementation does $location.search("foo", null) . I need a way to have two different spies for the same method depending on the arguments. I