我正在使用 React(react-create-app 和 TypeScript)。使用 Auth0 进行登录。
我想用 Jest 编写测试,我发现这个资源基本上是唯一关于模拟 Auth0 对象的内容。
所以我的代码看起来像这样:
import React from "react";
import ReactDOM from "react-dom";
import TopBar from "./index";
import {
useAuth0
} from "react-auth0-spa";
const user = {
email: "johndoe@me.com",
email_verified: true,
sub: "google-oauth2|12345678901234"
};
// intercept the useAuth0 function and mock it
jest.mock("react-auth0-spa");
describe("First test", () => {
beforeEach(() => {
// Mock the Auth0 hook and make it return a logged in state
useAuth0.mockReturnValue({
isAuthenticated: true,
user,
logout: jest.fn(),
loginWithRedirect: jest.fn()
}); …Run Code Online (Sandbox Code Playgroud)我必须使用 Node.JS 和 TypeScript 构建一个 rest API。我正准备用 Express,但看起来 Koa、Fastify 和 Hapi 可以提供更好的最新体验。
那么,在 2021 年使用 node 和 TS 构建 rest api 的现代选择是什么?
谢谢!
typescript ×2
auth0 ×1
express ×1
javascript ×1
jestjs ×1
koa ×1
node.js ×1
reactjs ×1
rest ×1