我有一个问题,我不知道如何解决,我在运行npm测试时遇到此错误Invariant Violation: You should not use <Switch> outside a <Router>.问题是什么,我该如何解决?我运行的测试是带有反应的标准app.test.js
class App extends Component {
render() {
return (
<div className = 'app'>
<nav>
<ul>
<li><Link exact activeClassName="current" to='/'>Home</Link></li>
<li><Link exact activeClassName="current" to='/TicTacToe'>TicTacToe</Link></li>
<li><Link exact activeClassName="current" to='/NumGame'>Quick Maths</Link></li>
<li><Link exact activeClassName="current" to='/HighScore'>Highscore</Link></li>
<li><Link exact activeClassName="current" to='/Profile'>Profile</Link></li>
<li><Link exact activeClassName="current" to='/Login'>Sign out</Link></li>
</ul>
</nav>
<Switch>
<Route exact path='/' component={Home}></Route>
<Route path='/TicTacToe' component={TicTacToe}></Route>
<Route path='/NumGame' component={NumberGame}></Route>
<Route path='/HighScore' component={HighScore}></Route>
<Route path='/Profile' component={Profile}></Route>
<Route path='/Login' component={SignOut1}></Route>
</Switch>
</div>
);
}
};
Run Code Online (Sandbox Code Playgroud) 尝试为安装reactjs时获得的App.test.js运行npm.test时出现此错误.有关如何解决这个问题的任何想法?我现在添加了一些额外的代码等.
> client@0.1.0 test /Users/filipmyllari/Documents/1DV430/fm222hp-
project/client
react-scripts test --env=jsdom
>2018-05-29 16:26 node[535] (FSEvents.framework) FSEventStreamStart:
register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2018-05-29 16:26 node[535] (FSEvents.framework) FSEventStreamStart:
register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:182
throw er; // Unhandled 'error' event
^
>Error: Error watching file for changes: EMFILE
at _errnoException (util.js:1019:11)
at FSEvent.FSWatcher._handle.onchange (fs.js:1360:9)
npm ERR! Test failed. See above for more details.
Run Code Online (Sandbox Code Playgroud)
这是package.json文件
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"add": "^2.0.6",
"babel-jest": "^23.0.1",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"firebase": …Run Code Online (Sandbox Code Playgroud)