Invariant failed: You should not use <Link> outside a <Router>
Getting this in trying to write a test for a component with
test("renders post list div ", () => {
const posts = [ {
created: '-',
title: '-',
slug : '-',
content : '-',
author : '-' } ];
const div = document.createElement('div');
ReactDOM.render(<PostList posts = {posts} />, div);
expect(div.querySelector("div")).toBeTruthy();
});
I use <Link ...
inside of a Post
which gets called within the main app
App itself uses Router like this:
return (
<ThemeContext.Provider value={theme} >
<Router>
<div className="App" style={{ paddingLeft: "10px" }}>
<Header text='Welcome' />
<PostMessage type={postMessage} setPostMessage={setPostMessage} />
<ChangeTheme theme={theme} setTheme={setTheme} />
<UserBar
username={username} setUsername={setUsername}
loggedIn={loggedIn}
onLogin={handleLogin} />
<br />
<hr />
<Switch>
<Route exact path='/'
...
{loggedIn && <PostList posts={posts} /> }
...
So I am within a Router tree. How to get the test to be able to do this also?