opencv-js
opencv-js copied to clipboard
Testing issue | Jest | Vitest
No meter which method from the lib I call it just paralyse the test and it just stuck. Even if I try to console.log it.
import cv from "@techstark/opencv-js";
test("My test", () => {
console.log(cv) // test will stuck
},
);
Any ideas why it might happen?
Could be because it's not initialised yet, you can try using onRuntimeInitialized, e.g. with Jest:
import cv from "@techstark/opencv-js";
const openCvLoadTimeout = 25000;
describe("opencvUtils", () => {
beforeAll(
async () =>
// wait for opencv to load
new Promise((resolve) => {
cv.onRuntimeInitialized = () => {
resolve(true);
};
}),
openCvLoadTimeout
);
See also https://github.com/TechStark/opencv-js/blob/main/test/cv.ts