我有一个Jest.spec.js
文件,正在导入我要测试的index.js
。
.spec.js
:
var HttpService = require('./index.js').HttpService;
问题如下:index.js
文件导入了一个有错误的.ts
文件。这似乎不是项目中的问题(我无法触摸该.ts文件(,而是I get the errors from that .ts file when I run my jest test!
index.js
:
var service_factory = require('../service-factory.ts');
service-factory.ts
:
import Loglevel from 'loglevel';
错误:Cannot find module 'loglevel' or its corresponding type declarations
;
window.App.services
错误:Property 'App' does not exist on type 'Window &typeof globalThis'
当我试图运行测试时,引用.ts file
。。
如有任何帮助,我们将不胜感激!谢谢
一个.js文件导入一个.ts文件是非常不寻常的。错误似乎就在那里。Js只能在typescript被转换为javascript后才能导入。看看是否有一个.js文件。如果没有,你可能需要先构建它。看起来就像是运行typescript时出现的错误,就好像它是JavaScript一样。