I need some help on testing a third party object. Below is my code
//app.js
export const specialFunction = (offer) => {
adobe.target.applyOffer({
mbox: 'container',
offer
})
}
adobe.target.getOffer({
mbox: 'container',
success: (offer) => {
specialFunction(offer);
}
})
in my test file
//app.test.js
import { specialFunction } from './app';
beforeAll(() => {
const adobe = {
target: {
getOffer: jest.fn(),
applyOffer: jest.fn()
}
}
window.adobe = adobe;
});
it('test function', () => {
specialFunction({foo: 'bar'});
expect(adobe.target.applyOffer).toHaveBeenCalledWith({
mbox: 'container',
offer: {foo: 'bar'}
});
})
but when I started to run it,app.js
always reports
ReferenceError: adobe is not defined
but if I change the app.js
to be
typeof adobe !== 'undefined' && adobe.target.getOffer({
mbox: 'container',
success: (offer) => {
specialFunction(offer);
}
})
then test passed, with the above adobe.target.getOffer
not tested
so my question is, how to test adobe.target.getOffer
part? and also why the test would pass? seems window.adobe = adobe
is working for the test case