Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine - ways of stubbing URL

I have the following line in my code:

var fileUrl = URL.createObjectURL(file);

Unfortunately phantomjs doesn't have URL so I need to stub it out in Jasmine, but not sure how.

I am using Jasmine 2 and AngularJS 1.4

like image 359
alexs333 Avatar asked Oct 19 '22 15:10

alexs333


1 Answers

spyOn(URL, 'createObjectURL').and.returnValue("something");

This assumes URL is accessible in your unit tests. Alternatively, another approach, is to define URL in your unit tests as ...

var URL = {
    createObjectURL: function() { return "something" }
}
like image 99
danday74 Avatar answered Oct 21 '22 06:10

danday74