我正在为tesseract ocr软件包编写测试。问题是使用cdn(<script src='https://unpkg.com/tesseract.js@v2.0.0-alpha.10/dist/tesseract.min.js'></script>
)将数据包导入了react index.html。必须进行测试,我无法在global(global.tesseract)或窗口(window.tesseract)中找到它。当我不断收到此错误时,如何将这个软件包放入测试文件中
TypeError:无法读取未定义的属性'TesseractWorker'。
我需要能够找到该软件包并测试该文件
import getDetails from '../getDetails';
describe('getDetails() function', () => {
const file = {
name: 'image.png',
};
const response = { data: {} };
const { TesseractWorker } = window.Tesseract;
const worker = new TesseractWorker();
it('should return ticket details', async () => {
worker ({
recognize: jest.fn(() => ({
progress: jest.fn().mockImplementation(() => Promise.resolve({
text:: `An updated look at all the ways that autonomous vehicles will change our lives in profound ways.`
}))
}))
});