Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 test with MockBackend returns Promise

I copied and use the same code as you can see in this question including the answer. My Angular dependency versions in package.json are set to 4.0.2, NodeJS has 7.5.0 and NPM has 4.1.2.

When I start the test response seems to be a Promise in my case.

expect(res).toBe(0); leads to the message Expected [object Promise] to be 0. on console. expect(res.length).toBe(0); ends with Expected undefined to be 0.

When I use the second example from official doc the same thing happens.

The same issue can recreated with Angular 4.0.0 dependencies.

Any ideas?

like image 801
hesch Avatar asked Dec 23 '22 18:12

hesch


1 Answers

Make sure you are importing the correct Response object.

import { Response } from '@angular/http';
like image 162
Nick Wyman Avatar answered Dec 28 '22 09:12

Nick Wyman