如何从CDN导入的包测试构造函数调用

时间:2019-06-09 04:35:37

标签: javascript unit-testing

我正在为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.`
 }))
      }))
    });

0 个答案:

没有答案