Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8936

Hapi.jsを使ったテストでauthの結果をモックする

$
0
0
Hapiはserver.injectというメソッドでサーバーをシミュレートすることができます。その中で「あるAPIをテストしたいが、authの結果をモックして返したい」という場面があると思います。その場合は const res = await server.inject({ method: "POST", url: `${baseUrl}/users`, auth: { // authを指定 strategy: "my-strategy", credentials: {}, artifacts: { name: "Admin User", admin: true, }, }, }); こんな感じでauthを指定するとそのテストで欲しいデータをrequest.authから取ることができました。

Viewing all articles
Browse latest Browse all 8936

Trending Articles