I'm trying to set a cookie in my test to make sure it's getting cleared out in my component:
import Cookies from 'universal-cookie';
test('successfully logs the user out', async () => {
const cookie = new Cookies()
cookie.set('authtoken', 'some-token')
const { getByText } = render(<Logout/>)
})
But in my Logout component the cookies object is empty:
export default function Logout() {
const [cookies, setCookie, removeCookie] = useCookies(['authtoken'])
console.log(cookies)
}
Is there another way to do this? Preferably one that isn't passing the cookie as a prop.
So the problem was what @Oleg and @Devin were hinting at. To render the provider as well. But I also had to pass the cookies as parameter like so:
import Cookies from 'universal-cookie';
test('successfully logs the user out', async () => {
const cookie = new Cookies({authtoken: 'some-token'});
const { getByText } = render(
<CookiesProvider cookies={cookie}>
<Router>
<Logout/>
</Router>
</CookiesProvider>
)
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With