使用 MSW 获取身份验证令牌| React-Redux-测试
我正在尝试使用 msw 库登录并遵循 Redux 文档。然后我想获取用户身份验证令牌。我正在发送登录请求,但不知道登录后如何获取身份验证令牌。示例中的结构对于登录正确吗?如果不是的话应该怎样
export const handlers = [
rest.post("/login", (req, res, ctx) => {
return res(
ctx.json({
id: "1234",
firstName: "John",
lastName: "Maverick",
})
);
})
const server = setupServer(...handlers);
// Enable API mocking before tests.
beforeAll(() => server.listen());
// Reset any runtime request handlers we may add during the tests.
afterEach(() => server.resetHandlers());
// Disable API mocking after the tests are done.
afterAll(() => server.close());
I'm trying to login using the msw library and following the Redux docs. Then I want to get the user auth token. I'm sending request for login but idk how to get auth token if logged in. Is the structure in the example correct for login? If not, how should it be
export const handlers = [
rest.post("/login", (req, res, ctx) => {
return res(
ctx.json({
id: "1234",
firstName: "John",
lastName: "Maverick",
})
);
})
const server = setupServer(...handlers);
// Enable API mocking before tests.
beforeAll(() => server.listen());
// Reset any runtime request handlers we may add during the tests.
afterEach(() => server.resetHandlers());
// Disable API mocking after the tests are done.
afterAll(() => server.close());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论