Используя react-scripts-ts (2.17.0), я пытаюсь настроить набор тестов. Но я получаю «SyntaxError: Неожиданный идентификатор».
Это конфигурация:
tsconfig.json (используя стандарт справочника JSX)
{
"compilerOptions": {
"jsx": "react"
}
}
Это макет компонента:
./App.tsx
interface IAppProps extends WithStyles<typeof styles> {
// ...
}
export interface IAppState {
// ...
}
class App extends React.Component<IAppProps, IAppState> {
// ...
}
export default withStyles(styles)(App);
И это будет тестовая установка:
./приложение.test.ts
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const app = React.createElement(App);
const div = document.createElement('div');
ReactDOM.render(app, div);
});
Должен ли я каким-то образом управлять Babel?





Оказывается, стили были загружены как es, а не определены по типу файла. Ответ найден здесь: https://github.com/mui-org/material-ui/issues/14349
Обновлено с "react-scripts-ts": "2.17.0" на "react-scripts-ts": "^3.1.0"
Затем изменил:
import withStyles from '@material-ui/core/es/styles/withStyles';
import { WithStyles } from '@material-ui/core/styles/withStyles';
К:
import { withStyles, WithStyles } from '@material-ui/core';
И это работает.