I have something like that
import {firstTableSettings} from "./firstTableSettings.js"
import {secondTableSettings} from "./secondTableSettings.js"
export default class CreateADTable {
constructor(settings) {
...
}
...
}
let tablesSettings = [firstTableSettinhs, secondsTableSettings]
function createTable() {
for(let setting of tablesSettings) {
new CreateADTable(setting)
}
}
createTable() //during jest test it generate problem, but I need it here
Because in JavaScript, import immediately calls the createTable method, the class is created with the original data. firstTableSettings and secondTableSettings contain calls to endpoints using axios, and many other things that prevent the test environment from being isolated (at least that’s how it looks). I would like to have full control over what is pushed to the class during test. And even if my test passes fine, I see that the method calling the class with the original methods is run anyway. Is it possible to somehow suppress the createTable method so that it doesn’t get called at all? What should the test architecture be for such a case? Or maybe I shouldn’t worry about errors related to the fact that the class with the original data is called first?
I tried some mock, but always was something wrong or mock looked like not working.