0

I've used jest automock as I'm facing nested namespace issues for my unit testing of a jQuery application.

module.exports = {
                automock: true;
                 }

I'm mostly there, used code from Jon G


const jQ = jest.requireActual("jquery");

const get = jest.fn((path) => {
    return Promise.resolve(path);
});

const when = jest.fn((prom1, prom2, prom3, prom4) => {
    return Promise.resolve();
});

const jQuery = jQ;
jQuery.get = get;
jQuery.when = when;
exports.jQuery = jQuery;

I need the .find functionality unmocked

Ideally i want to use the jest.spyOn() feature to mock internal anonymous function calls which otherwise return as undefined, so I've ended up using babel-plugin-rewire to allow me to import the functions unaccessible to spyOn()

The function looks like

var XYZ = XYZ || {};
XYZ.Utils = (function () {
var functionName = function (blahblahblah) {
var x = XYZ.OtherNameSpace.usefulFunction(blahblahblah)
return x
}

And is called by

XYZ.Utils.functionName(blahblahblah)

I want to mock var x = XYZ.OtherNameSpace.usefulFunction(blahblahblah) because jest can't see it and returns undefined. Thus automocking, please help, I didn't write it this poorly coupled.

Adi C
  • 1
  • 2

0 Answers0