Questions tagged [angular2-testing]

289 questions
1
vote
1 answer

Angular2 Testing: Service returning function instead of object array

I want to write some tests for my service written in Angular 2.1.0: @Injectable() export class MyService { api_base_url = 'http://' + environment.apiHost + ':5000/api/'; constructor(private http: Http) { } getMyObjs(query):…
fivunlm
  • 462
  • 1
  • 6
  • 15
1
vote
1 answer

Angular 2 Final Release Router Navigate Unit Test Error

I am getting Failed: Uncaught (in promise): Error: Cannot find primary outlet to load 'UserList' error. This happens when unit testing my login component that redirects to admin/userlist using this._router.navigate(['admin/userlist']); in the…
1
vote
1 answer

Angular 2 keeps adding "/testing" to the end of my file imports - systemjs

I've just started to add unit tests to my angular 2 app and I am having a nightmare, every time I have to import something new into my app that I haven't used before, it adds "/testing" to the end of each…
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
1
vote
1 answer

angular 2 MockBackend test http timeout?

Is there a way to test http timeout behaviour of a service? I'm using MockBackend even when setting job's timeout to 0 no logging of 'TIMEOUT' present. export class MyHttpService { private sendGetRequest (job: HttpJob): Observable { return…
Petr Marek
  • 1,381
  • 1
  • 15
  • 31
1
vote
0 answers

Whats mistakes with this angular2 unit test setup?

my application is running good but unit test doesn't work. below error throws when i try to npm test ** help me to resolve my issue and whats the correct procedure to follow angular2 unit test, thanks in advance.. package.json { "name":…
1
vote
1 answer

How to get json data from service method call to test case using angular2 unit testing with karma-Jasmine?

I have trying to get json data from when i calling service method. I got a return object but i didn't get json data. Which part i have to change? "goods.services.ts" getAllData(): Observable{ let jwtTok1 ="Something"; let headers =…
Sithu05
  • 146
  • 5
  • 12
1
vote
1 answer

How to reduce speed of e2e test in angular2 using protractor?

I am running e2e test cases for angular2 app using protractor. So far my tests are getting compiled & results are generated. But I cant see whats happening on browser as operations are quite fast. I want to know how to reduce the speed of these test…
Bhushan Gadekar
  • 13,485
  • 21
  • 82
  • 131
1
vote
0 answers

Testing root component: Angular 2 testing

I'm trying to test my angular 2 app which obviously has a root component. The root component has nothing technical in its class body, it is just importing the child components and calling child components in its html file (with child component…
Aiguo
  • 3,416
  • 7
  • 27
  • 52
1
vote
0 answers

calling and executing a component's function: Angular2 testing

I'm trying to test a component, which has a constructor with multiple parameters. In the testing file (spec file), I've created a componentInstance using: componentObject: fixture.componentInstance; Also, I'm using this object to call a function…
Aiguo
  • 3,416
  • 7
  • 27
  • 52
1
vote
0 answers

unit testing for Angular2 using TestBed for component with async service

I'm using Angular 2.1.0. I have a very simple asynchronous service: @Injectable() export class Service { protected str: Subject; constructor() { this.str = >new Subject(); } getStream():…
koral
  • 2,807
  • 3
  • 37
  • 65
1
vote
1 answer

component = new componentClass() VS. component = fixture.createInstance: Angular2

According to the Angular2 testing documentation, for testing components we should create an object like this: component = fixture.createInstance; but for isolates unit testing, like for service, it is said to create an instance like this: component…
Aiguo
  • 3,416
  • 7
  • 27
  • 52
1
vote
1 answer

Testing forms: angular2 testing

I'm trying to test a component that has imported 'FormGroup' and 'FormBuilder', but when I'm trying to run the test file for that component it gives me an error saying 'FormGroup' and 'FormBuilder' isn't a known property of form. I tried doing…
Aiguo
  • 3,416
  • 7
  • 27
  • 52
1
vote
1 answer

mockBackend = getTestBed().get(MockBackend);?

I am learning testing Angular 2 with Karma, and was wondering about some points in code I didn't understand. After the TestBed "mock module" is configured, the following code runs: mockBackend = getTestBed().get(MockBackend); What does this do?…
VSO
  • 11,546
  • 25
  • 99
  • 187
1
vote
1 answer

Angular 2 testing

I have a component. Hes main role to be wrapper. In what trouble? When method compileComponents executing the component has no property title. Thats why, as i think, in console i see error Question is: How i can first bind property and then run…
Tapakan
  • 328
  • 1
  • 3
  • 15
1
vote
1 answer

Angular 2 testing Router with Jasmine and Karma

I am having issues writing a stub for router.navigate in angular 2. I currently have the below stub written. Which is what shows up in the angular docs. @Injectable export class RouterStub { navigate(commands: any[], extras?: NavigationExtras)…