jasmine

Angular 2 Jasmine testing, Loading all components in app.component.ts?

梦想与她 提交于 2019-12-01 12:18:45
I'm working on a small test app to learn Angular 2 and unit testing in Angular 2 a bit better. Coming from a react - Jest background; it feels weird to include all components in the app.component.ts. This is what the component Hierarchy looks like for what I have so far: App.Component > Layout.Component > Header.Component > Nav.Component When I run npm test, I get the error of main-header' is not a known element: When I'd fix this by Importing and declaring the component bound to that selector in App.Component.spec.ts, I would just get the same error for the next component/selector inline. Had

How to unit test $http in angularjs and Jasmine

て烟熏妆下的殇ゞ 提交于 2019-12-01 12:10:09
问题 Here is my code, I've made a Plunker as the code is long: describe("create", function(){ it("Should be defined", function(){ expect(BaseService.create).toBeDefined(); }); it("it should POST to http://api.test.com/TEST/", function(){ /*** * * NOT TO SURE WHAT TO DO HERE * */ }) }); http://plnkr.co/edit/s8P2XlkfR6HfGuj8WIcb I am new to Unit Testing so I am having a bit of trouble working out how to assert the following: If the method is going to x url If the method is using x method (e.g. GET,

Angular 2 rc5 , unit testing issue with pipes that use injection

半世苍凉 提交于 2019-12-01 11:34:12
I am using angular2 rc 5, I have written a custom pipe that fetches value from a json. The custom pipe : literal.pipe.ts looks like : import {Pipe, PipeTransform, Inject} from '@angular/core'; import {MessageService} from '../service/message.service'; @Pipe({ name: 'literalString', pure: false }) export class LiteralPipe implements PipeTransform{ private messageBundle:any; private request:any; constructor(private _messageService: MessageService){ this._messageService = _messageService; this.messageBundle = {}; } transform(value:string, args:string[]):any { if(!this.request){ this.request =

protractor-jasmine2-html-reporter doesn't consolidate results for all test when tests are shared using 'shardTestFiles': true in conf file

五迷三道 提交于 2019-12-01 11:06:29
Recently we have configured our e2e-tests to be on Jenkins & soon we realized that we have to use shared test files: true options as complete suite run is taking very long time for us peeking 9-10hrs on daily basis. but when we configured below two options in conf file. tests are running fine but final report displays only the last specs run results in save path. consolidate all options is not giving the full reports. please find our conf file details. any help will be appreciated. Edit the conf file as per solution provide by Aditya. please help var Jasmine2HtmlReporter = require('protractor

Custom message on wait timeout error

寵の児 提交于 2019-12-01 11:03:10
From time to time I'm using "Expected Conditions" feature introduced in protractor 1.7. Use case : var EC = protractor.ExpectedConditions; browser.wait(EC.visibilityOf(header.displayName), 10000); where header is a Page Object. If header.displayName would not become visible in 10 seconds, an error would be thrown: [firefox #4] 2) Describe description here [firefox #4] Message: [firefox #4] Error: Wait timed out after 10082ms [firefox #4] Stacktrace: [firefox #4] Error: Wait timed out after 10082ms [firefox #4] ==== async task ==== [firefox #4] at [object Object].<anonymous> (/Path/to/project

Observable.fromPromise empty during unit testing

邮差的信 提交于 2019-12-01 11:02:12
loadAdList$ is an Observable that taps into the actions$ stream: loadAdList$: Observable<Action> = this.actions$ .ofType<adActions.Load>(adActions.LOAD) .switchMap((action) => { return Observable.fromPromise(store.findAll('ad', action.payload) .then((ads) => { return new adActions.LoadSuccess(ads); }) .catch((err) => { return new adActions.LoadFail(err); })); }); It works in the browser, there is no problem with it. However, I want to unit test it as well: actions$ = hot('-a', { a: loadAction }); const storeResponse = Promise.resolve(mockAds); const expected$ = cold('-c', { c:

Angular 2 Jasmine testing, Loading all components in app.component.ts?

自古美人都是妖i 提交于 2019-12-01 10:26:50
问题 I'm working on a small test app to learn Angular 2 and unit testing in Angular 2 a bit better. Coming from a react - Jest background; it feels weird to include all components in the app.component.ts. This is what the component Hierarchy looks like for what I have so far: App.Component > Layout.Component > Header.Component > Nav.Component When I run npm test, I get the error of main-header' is not a known element: When I'd fix this by Importing and declaring the component bound to that

Error on Jasmine - Expected event click to have been triggered on #DIV_ID

久未见 提交于 2019-12-01 10:22:15
问题 I am referred this link to trigger a event when developing a testing tool in Jasmine framework: http://www.htmlgoodies.com/beyond/javascript/js-ref/testing-dom-events-using-jquery-and-jasmine-2.0.html I am trying to get the newly applied CSS attribute after triggering a click event on #DIV_ID in Jasmine framework. I am tried this code: spyEvent = spyOnEvent('#DIV_ID', 'click'); $('#DIV_ID').trigger( "click" ); expect('click').toHaveBeenTriggeredOn('#DIV_ID'); expect(spyEvent)

Anyway to use OR in expects for Protractor

旧巷老猫 提交于 2019-12-01 09:28:51
It is possible to do a x.toEqual('hello').or.toEqual('bye') ? I want to be able to do Expects that have multiple correct possibilities. You can always do an if statement that returns a boolean and then check if that boolean is true. var test = false; if(x=='hello' || x=='bye'){ test = true; } expect(test).toEqual(true); 来源: https://stackoverflow.com/questions/24434826/anyway-to-use-or-in-expects-for-protractor

Karma-Jasmine: How to properly spy on a Modal?

走远了吗. 提交于 2019-12-01 09:28:22
THE SITUATION: I am unit testing my Angular / Ionic app. I am having troubles with the modal. At the moment i can test that the modal has been called. That's all so far. I cannot test the proper show() and hide() method of the modal. I am getting the following errors: TypeError: $scope.modal_login.show is not a function Error: show() method does not exist TypeError: $scope.modal_login.hide is not a function Error: hide() method does not exist I think it depends entirely on the spy. I don't know how to properly spy on the modal, and i think that once that is done, everything will work fine. THE