I'm trying to unit test a module (using tapejs) that is dependent on another module that uses the document object and i get "ReferenceError: document is not defined"
// My module i want to test
import { createUrl } from '../config/paths';
// Paths.js
export const url = document.location.toString(); // This is where i'm getting the error.
I tried proxyquire to proxy this dependency but it doesn't seem to do anything.
const store = proxyquire('../../../store/list-store', {
'../config/paths': {
createUrl: stub(),
},
});
Any suggestions?
Using proxyquire's noCallThru method helped me achieve this.
According to proxyquire's docs:
By default proxyquire calls the function defined on the original dependency whenever it is not found on the stub.
If you prefer a more strict behavior you can prevent callThru on a per module or contextual basis.
My solution:
const proxyquireStrict = proxyquire.noCallThru();
const Store = proxyquireStrict('../../../store/booking-add-store', {
'../config/paths': {
createUrl: () => stub().returns(''),
},
}).default;
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