I am trying to provide a different value for
document.referrer
for my unit tests. How can I mock it and provide a customized value?
Inspecting document.referrer
, we find that it is a getter:
With Jasmine 2.6, you can create a spy to change the return value of any getter functions.
spyOnProperty(document, 'referrer', 'get').and.returnValue('http://foobar.com');
expect(document.referrer).toBe('http://foobar.com');
You can read more in the latest API documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With