基本上,我开始研究测试,并且我正在尝试测试一个函数,以检查一个值是否在笑话中为Class类型。
我的isClass.spec.ts :
import { isClass, ClassType } from './isClass';
describe('Verify if parameter is typeof class', () => {
it('Expect true when value is typeof class or false if not typeof class', () => {
class test {}
const result = isClass(new test());
expect();
});
})
我的isClass.ts
export type ClassType = { new (...args: any[]): any };
export const isClass = (object: any): object is ClassType => {
return object;
};
我的纱线测试中出现此错误:
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Details:
/home/spirit/Documentos/spt-bootstrapApp/src/utils/isClass.spec.ts:1
import { isClass, ClassType } from './isClass';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime._execModule (node_modules/jest-runtime/build/index.js:1179:56)
我的jest.config.js:
const { compilerOptions } = require('./tsconfig.json');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
module.exports = {
clearMocks: true,
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>',
}),
preset: 'ts-jest',
testEnvironment: 'node',
};