How to write the test case in Jasmine in Angular2 for redirect URL?

531 views Asked by At
SecurityService.prototype.Feedback = function () {
    window.open('https://www.google.com/', '_blank');

I need to write the test case for above code in Jasmine in Angular 2.

1

There are 1 answers

0
Pedro Vaz On

I'd recommend you to use $window instead of window.

If you do that, you can easily test it like this:

spyOn($window, 'open');

//call your function here

expect($window.open).toHaveBeenCalledWith('https://www.google.com/', '_blank');

Hope that helps.