我使用 mocha 从命令行测试 tsx 组件。我用于编译 ts-node 包。但它不能编译 jsx。我的 tsconfig.json 有 jsx 编译选项。
mocha --compilers ts:ts-node/register,tsx:ts-node/register,js:babel-core/register ./src/testing.tsx
SyntaxError:Exports.runInThisContext (vm.js:53:16) 处的意外令牌 <
tsconfig.json :
{
"compilerOptions": {
"experimentalDecorators": true,
"module": "commonjs",
"jsx": "preserve",
"target": "es6",
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": false,
"noEmitHelpers": false,
"noEmitOnError": false,
"noImplicitAny": false
},
"exclude": [
"babel_cache",
"build",
"docs",
"gradle",
"node_modules",
"out",
"test",
"tools",
"typings"
],
"compileOnSave": false,
"buildOnSave": false
}
/src/testing.tsx :
import * as React from 'react';
class Foo extends React.Component<any, any> {
render () {
return <span>yep</span>;
}
}
<Foo />