I am trying to mock a class using Jest and I am using raw JS for that. But raw JS always comes after imports in bs.js file irrespective of its order in .res file. The import won’t be mocked if it is imported before jest mocks it. Utility is the class that needs to be mocked. The function getComponentJSONByID from Utility is imported inside VideoScrub module.
.res looks like this.
%raw(`jest.doMock('app/utilities/utility.ts', () => {
return class Utility {
static getComponentJSONByID(componentID) {
return {
duration: {
absolute_start: 1.0,
absolute_end: 6.2,
absolute_duration: 5.2,
},
};
}
}
})`)
open Jest
open Expect
open VideoScrub
bs.js looks like this
var Jest = require("@glennsl/bs-jest/src/jest.bs.js");
var VideoScrub = require("./VideoScrub.bs.js");
var Caml_exceptions = require("bs-platform/lib/js/caml_exceptions.js");
((jest.doMock('app/utilities/utility.ts', () => {
return class Utility {
static getComponentJSONByID(componentID) {
return {
duration: {
absolute_start: 1.0,
absolute_end: 6.2,
absolute_duration: 5.2,
},
};
}
}
})));
Any help on this would be appreciated.