简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM