Questions tagged [angular2-testing]

289 questions
6
votes
1 answer

Angular 2 / Ionic 2 TypeError: zxcvbn_1.default is not a function

Testing with Jasmine and Karma, I am using the zxcvbn library to do some password strength calculations. This fails when I try to run a spec on it, by calling the updateScore() function below. private updateScore(): void { const analysis =…
Ka Mok
  • 1,937
  • 3
  • 22
  • 47
6
votes
1 answer

How to test @ionic/storage?

I need to test my service where I'm using @ionic/storage to get and set data in a method. Do I need to mock the whole storage mechanism or what would be the best practice for that?
mrp
  • 689
  • 1
  • 8
  • 17
6
votes
2 answers

Unit testing Angular 2 authGuard; spy method is not being called

I'm trying to unit test my auth guard service. From this answer I was able to get this far, but now when I run the unit test for this, it says Expected spy navigate to have been called. How to I get my spied router to be used as this.router in the…
coblr
  • 3,008
  • 3
  • 23
  • 31
6
votes
2 answers

'expect' was used when there was no current spec

I am learning Angular 2 testing and I am getting an error that currently doesn't make sense to me. 'expect' was used when there was no current spec, Test: import {ExperimentsComponent} from "./experiments.component"; import {StateService} from…
Mike3355
  • 11,305
  • 24
  • 96
  • 184
6
votes
2 answers

Angular 2 Unit Testing Observable Errors (HTTP)

I am trying to write unit tests for my API service but have some trouble catching HTTP errors. I am following this guide along with the Angular2 docs since the guide is (slightly) out of date in some minor areas. All unit tests pass apart from those…
6
votes
2 answers

Angular2 - Unit testing Observable error "Cannot read property 'subscribe' of undefined"

I have a service function which is returning Observable and I am consuming that service inside one of my components. I have written a unit test for the component using the technique posted here. However, strangely I am getting "cannot read property…
A J Qarshi
  • 2,772
  • 6
  • 37
  • 53
6
votes
1 answer

angular 2 unit tests not able to find debugElement

I am trying to run unit tests on my component which is an output for my router. I have stubbed the router and service used by the component and I am trying to pull the element using the fixture.debugElement to confirm the tests are working. …
Paul Mooney
  • 61
  • 1
  • 2
6
votes
3 answers

Angular 2 Custom validation unit testing

i'm writing custom angular(Angular 2.0.0) validation, following this guide https://angular.io/docs/ts/latest/cookbook/form-validation.html#!#custom-validation . @Directive({ selector: '[ngModel][emailValidator]', providers: [{provide:…
6
votes
3 answers

Angular2 testing with Jasmine, mouseenter/mouseleave-test

I've got a HighlightDirective which does highlight if the mouse enters an area, like: @Directive({ selector: '[myHighlight]', host: { '(mouseenter)': 'onMouseEnter()', '(mouseleave)': 'onMouseLeave()' } }) export class…
bene
  • 798
  • 7
  • 19
5
votes
2 answers

Typescript opposite / reverse operation of "typeof"

Angular can Query subComponents by Types, which is used in Testing like this: fixture.debugElement.query( By.directive( ComponentType ) ); Now i wanted to make a function which does this for me: import { ComponentFixture } from…
5
votes
2 answers

how to get arguments on an event emitter in jasmine test

I have a unit test as below it('billing information is correct', () => { fixture.detectChanges(); spyOn(component.myEventEmitter, 'emit').and.callThrough(); component.form.controls['size'].setValue(12); fixture.detectChanges(); …
Josf
  • 776
  • 1
  • 8
  • 21
5
votes
1 answer

Angular 2 - Unit test binding to nested custom form control

I've got a custom from control with selector app-date-picker. It implements ControlValueAccessor. I have a component called MyPage that contains this custom form control via:
5
votes
2 answers

Testing: blur emulate

I would like to test simple angular component with input. So an example in the bottom has little preparation for the test, and in a component should occur test function on blur, which shows log, but I have no logs in console. I tried 2 cases:…
qwe asd
  • 1,598
  • 3
  • 21
  • 31
5
votes
0 answers

Angular2 unit testing does not update input's ngModel when used inside a form

I have fairly extensive testing in our Angular 2.4 based application. One area we have not been able to test though is forms with inputs. I finally tracked this down to a small test case. I have a plnkr that shows the issue:…
Allen
  • 3,134
  • 5
  • 29
  • 49
5
votes
3 answers

Angular2 Testing "Cannot find name 'HTMLElement'"

I'm trying to introduce testing into my existing project, but I keep running into the same error, which I think is prohibiting me from running the tests. The error I get is ERROR in .../src/app/dashboard.component.spec.ts (15,13): Cannot find name…
Christian
  • 195
  • 1
  • 2
  • 10