Here is the code that needs to be mocked:
const P = {
scripts: {
getScripts: (name?: any) => {
// do some stuff and return json
return { foo: 'value'};
}
}
}
export default P;
The code needing to be tested:
export const getScripts = (name?: string) => {
return P.scripts.getScripts(name); // I want a mock being called here
};
I have successfully used sinonJS for my tests:
const fakeGetScript = sinon.fake.returns({
foo: 'fakeValue'
});
However, I am struggling to replace the original getScript
function of P
with my fake one.
Any suggestions on how to achieve this?