Jest cannot load script tag content, so jsonp cannot be tested

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.

The code for

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

Jun.09,2021

Oh, my God, I found you again. Is there a solution to this problem?


jest.timeout set a longer number

Menu