mardi 12 avril 2016

Unit Testing/mocking Window properties in Angular2 (TypeScript)

I'm building some unit tests for a service in Angular2.

Within my Service I have the following code:

var hash: string; hash = this.window.location.hash;

However when I run a test which contains this code, it will fail.

It'd be great to utilise all the features of Window, but as I'm using PhantomJs, I don't think this is possible (I have also tried Chrome which yields the same results).

In AngularJs, I would have resorted to mocking $Window, but as there is not a lot of documentation for Angular2 Unit Testing I'm not sure how to do this.

Can anyone help?

Aucun commentaire:

Enregistrer un commentaire