I am wondering how can I spy/stub function on Jasmine if I am using ES6 imports/exports with babel?
import MobileDetect from 'mobile-detect';
it('should spy MobileDetect', () => {
MobileDetect = jasmine.createSpy('MobileDetect');
});`
The first problem is that I can't rewrite read-only module
Module build failed: SyntaxError: /Users/oleg/projects/rp/popup/lib/spec/popup.spec.js: "MobileDetect" is read-only
it('should spy MobileDetect', () => {
console.log(MobileDetect.prototype.constructor === MobileDetect); //true
spyOn( MobileDetect.prototype, 'constructor' );
console.log(MobileDetect.prototype.constructor === MobileDetect); //false
});`
I tried this approach, but it doesn't work too... MobileDetect.prototype.constructor spied, but MobileDetect directly not.
What do you think about this problem?
MobileDetect
because the variable's value can't be rewritten to a new spying function. My guess: what if you didvar myMobileDetect = MobileDetect
and then spied onmyMobileDetect
instead? Obviously, you'd need to change your code to usemyMobileDetect
, though. – ZacatecasMobileDetect
's methods? (ie a mock) – Somersomers