jasmine

Spec has no expectation console error although expect is present

拈花ヽ惹草 提交于 2020-07-09 05:25:10
问题 I have the spec that has to expect still it says there are no expectations... it('should click on yes button of technician and check save&continue functionality', () => { const saveAndContinue = fixture.debugElement.query(By.css(saveContinueBtn)).nativeElement; saveAndContinue.click(); fixture.detectChanges(); fixture.whenStable().then(() => { const spy = spyOn(component, 'isSaveAndContinueClicked').and.callThrough(); expect(component).toBeDefined(); expect(spy); component

How to do jasmine unit test case for angular 6 bootstrap 4 modal

浪子不回头ぞ 提交于 2020-07-07 07:38:06
问题 html <ng-template #content let-modal> <h1>Modal content inside this ng-template #content </h1> </ng-template> Button to open model <button (click)="open(content)" > Open modal </button> In ts file import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; constructor( public modalService: NgbModal) { } open(content) { this.modalService.open(content, { ariaLabelledBy: 'modal-basic-title', size: 'lg' }).result.then((result) => { this.closeResult = `Closed with: ${result}`; },

Is there an Array equality match function that ignores element position in jest.js?

无人久伴 提交于 2020-07-05 05:16:39
问题 I get that .toEqual() checks equality of all fields for plain objects: expect( {"key1":"pink wool","key2":"diorite"} ).toEqual( {"key2":"diorite","key1":"pink wool"} ); So this passes. But the same is not true for arrays: expect(["pink wool", "diorite"]).toEqual(["diorite", "pink wool"]); There does not seem to be a matcher function that does this in the jest docs, i.e. that tests for the equality of two arrays irrespective of their elements positions. Do I have to test each element in one

Run javascript es6 code in Jasmine

两盒软妹~` 提交于 2020-07-03 03:29:08
问题 I am exploring JavaScript es6 code in angularjs app and used grunt babel to compile the es6 to es5. My unit test (jasmine) doesn't run with es6 code using phantomjs. Whats best way to run test? Is there any plugin to use for jasmine to run es6 code? 回答1: You can configure Jasmine to use Babel as a helper and transform your code on the fly. Install babel-register module: npm install --save-dev babel-register And register it as a Jasmine helper In your spec/support/jasmine.json file make the

How to unit test a function is called correctly after a timer has fired. Angular 7, RXJS 6

余生长醉 提交于 2020-06-29 06:25:12
问题 In my Angular 7 application, I have a service that is used to track active user tasks. In the service, a timer runs every second to check if any tasks still haven't been completed within 30 seconds. If any tasks are found to have expired, the task is emitted via an event emitter on the service to be handled elsewhere. This all works when the app is running in a browser, but when I try to write a unit test to test the behavior in a fakeAsync environment, tick(X) does not advance the time ( or

Testing async HTTP-based function with Jasmine and await: Expected one matching request for criteria “…”, found none

一个人想着一个人 提交于 2020-06-29 05:20:54
问题 WHAT: Testing an async function that uses await WITH: Angular 9, Jasmine 3.4.0 Minimal code to reproduce: StackBlitz I have a function like this. Note, that it has to await this.getHeaders(). Whenever I remove await and replace the implementation of getHeaders() by some synchonous implementation, the test runs successfully. What is the correct way to test it? private async loadUserData() { // Try to remove await - the test runs successfully //const headers = this.getHeaders(); const headers =

How to write into a particular cell using xlsx npm package

不打扰是莪最后的温柔 提交于 2020-06-26 08:14:22
问题 I have to write a value to a particular cell (say the D4 cell) in my xlsm file. I can see the option of XLSX.writeFile(workbook, 'out.xlsx'); in https://www.npmjs.com/package/xlsx#writing-functions to write , but I am not seeing anything to write a value to a particular cell(where should the values which needs to be written passed ?). Or, it is not as clear as the example provided to read a particular cell value. Would be glad if someone could provide me a simple example of snippet. This is

How to exclude mock files from Code Coverage Istanbul Reporter

烂漫一生 提交于 2020-06-13 19:02:12
问题 I have a question regarding Istanbul Reporter used for reporting my unit testing coverage in my angular 6 application. My problem is: when the coverage is rendered, I see the mocks in the tested files list and obviously the mocks aren't tested, which gives me wrong coverage stats. This is my karma.conf file setup by a colleague and I'd like to know if you have any idea on how to exclude those mock files. module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine', '

How to cover the test for form control in angular? (Stackblitz attached)

空扰寡人 提交于 2020-06-13 05:59:06
问题 I am making a simple application which has an input field and a button and on click of the button an api call was made and respective response is fetched. Everything working fine with this. Things done as of now: I am making a validation and display the error message via a function like, hello.component.ts : controlErrors(formControl: AbstractControl | FormControl): string { if ( formControl && formControl.touched && formControl.invalid && formControl.errors ) { return Object.keys(formControl

How to unit test return value of function - Angular (Jasmine/Karma)

試著忘記壹切 提交于 2020-06-12 04:54:57
问题 I am wondering if there is a way to correctly test the return value of a function in Angular. I want to essentially test the return value to be true for one test and write another to test the opposite scenario. Ts component: get() { if (this.object == undefined) { return true; } else { return false; } } The only way I can see fit right now to test the return value is to set a variable to hold the return value. Below is my attempt, I'm just stuck on asserting what is to be expected. Test: it(