Closed dman777 closed 7 years ago
@dman777 In the output, I don't see the assertion failing, so the stub is getting called.
Could you try moving fetch.resolves(response);
below the proxyquire? I'm not sure that would help anything, but maybe worth a try.
No success on that. However, using proxyquire global worked. Thanks for the response and suggestion though.
describe('lifx alert test', ()=> {
it('should run fetch', ()=> {
var fetch = sinon.stub().returnsPromise();
var body = {
"hourly": {
data:
[ { time: 1493413200,
icon: 'clear-day',
precipIntensity: 0,
precipProbability: 0,
ozone: 297.17 },
{ time: 1493416800,
icon: 'clear-day',
precipIntensity: 0,
precipProbability: 0,
ozone: 296.89 },
{ time: 1493420400,
icon: 'clear-day',
precipIntensity: 0,
precipProbability: 0,
ozone: 296.73 },
{ time: 1493424000,
icon: 'clear-day',
precipIntensity: 0,
precipProbability: 50,
ozone: 296.31 } ]
}
};
var response = { json: () => { return body } };
fetch['@global'] = true;
fetch.resolves(response);
proxy('../index.js', {'node-fetch': fetch});
fetch.should.have.callCount(3);
});
});
I am trying to stub a fetch call with sinon. sinon-stub-promise, proxyquire, and mocha. I'm pretty close...but I am not sure why the stub containing my function response.json() method isn't invoking when it is clearly there.