problem description
use the Jest framework to test a jsonp
code, but the JsDom used by Jest seems to be unable to load the contents of the script
tag, resulting in the global function of jsonp
cannot be called. Therefore, the jsonp
can not be done unilaterally.
jsonp
is as follows:
import { jsonp } from "../src/jsonP";
test("jsonp", done => {
jsonp("https://fake-collect.com", {a: "b"}, (err, data) => {
expect(data).toBeTruthy();
done();
})
})
but each time a Error: ReqDynamic params Timeout
error is thrown in the jsonp
code, which represents a request timeout. Indicates that script
cannot be caused by proper loading.
expected results
can run the whole process of jsonp correctly in the Jest framework, load the
script` tag and the procedure that the global function is called