我正在尝试在我的测试中设置一个 cookie,以确保它在我的组件中被清除:
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/>)
})
但是在我的 Logout 组件中,cookies 对象是空的:
export default function Logout() {
const [cookies, setCookie, removeCookie] = useCookies(['authtoken'])
console.log(cookies)
}
还有另一种方法可以做到这一点吗?最好是不将 cookie 作为道具传递的。