I need to get some real data in my tests from a remote url. The superspy is not mocking. I did this by including node_modules/superagent/ in unmockedModulePathPatterns .
This is the file I'm trying to check, the .end() function is never called.
This is my test that fails with a timeout error.
jest.dontMock("../Stocks.js"); jest.dontMock("superagent"); describe("Stock Actions", () => { var makeRequest = require('../Stocks') pit("doesn't crash", function () { var promise = makeRequest("Hello World") promise.then(function (str) { expect(str).toBe("yay"); }); return promise; }); });
And this is the module that he is trying to check:
import Reflux from 'reflux'; import request from 'superagent'; console.log("request-superagent", request) const makeRequest = Reflux.createAction({ asyncResult: true }); const Store = Reflux.createStore({ init() { this.listenTo(makeRequest, 'onMakeRequest'); }, onMakeRequest(url) { request('GET', 'http://api.example.com/list/') .end(function (err, res) { console.log("res.text", res.text); if (!res.ok) { makeRequest.failed("aw"); } makeRequest.completed("yay"); }); } }); module.exports = makeRequest;
How to use superagent in jest-cli?
Rollo source share