看起来它们应该是这样,因为组件内的 props 永远不应该改变。我在 Google 或 Stack Overflow 上找不到任何答案,所以在这里提问只是为了确定一下。
我在我的useMediaQuery()一个组件中使用 Material-UI 的函数来确定size要<Button>在组件内使用的道具。
我正在尝试测试它在玩笑测试中是否按预期工作,但是我当前的实现不起作用:
describe("Unit: <Navbar> On xs screens", () => {
// Incorrectly returns `matches` as `false` ****************************
window.matchMedia = jest.fn().mockImplementation(
query => {
return {
matches: true,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn()
};
}
);
it("renders as snapshot", async () => {
const width = theme.breakpoints.values.sm - 1;
const height = Math.round((width * 9) / 16);
Object.defineProperty(window, "innerWidth", {
writable: true,
configurable: true,
value: width
});
const { asFragment …Run Code Online (Sandbox Code Playgroud) fireEvent.focus()我在调用后无法拍摄快照。
这是测试。我这里有两个测试,1 比较输入聚焦之前的快照,1 比较输入聚焦之后的快照。
\n\ndescribe("Unit: <OutlinedInput />", (): void => {\n\n describe("Initial render", (): void => {\n describe("renders as snapshot", (): void => {\n it("for standard fields", (): void => {\n const { asFragment } = render(<OutlinedInput {...standardProps} />, {});\n expect(asFragment()).toMatchSnapshot();\n });\n });\n });\n\n describe("On focus in, no input", (): void => {\n describe("renders as snapshot", (): void => {\n it("for standard fields", (): void => {\n const { getByLabelText, container, asFragment } = render(\n <OutlinedInput {...standardProps} …Run Code Online (Sandbox Code Playgroud) 我有一个具有语音和短信功能的 Twilio 手机号码。我可以在 Zoiper 中拨打和接听电话,但我不知道如何设置它以便我也可以发送/接收短信。没有关于如何执行此操作的指南。我该如何设置?
我使用的是 Typescript,它从src/到lib/文件夹进行编译,而 Babel,它从lib/到进行编译dist/。
我遇到的问题是,当我编译应用程序时,.handlebars其中的文件src/email_templates/没有被复制到。dist/因此,当我运行该应用程序时,它会失败并出现错误,因为它dist/email_templates/不存在。
我正在使用nodemailer-handlebars包并尝试将email_templates/文件夹移动到项目根目录并设置viewPath为该文件夹,但是这也会失败,因为应用程序位于var/www/api.my-domain.com/. 似乎api.my-domain.com文件夹名称中有句点会导致 viewPath 失败并出现错误:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
at validateString (internal/validators.js:125:11)
at Object.resolve (path.js:1080:7)
at ExpressHandlebars._resolveLayoutPath (/var/www/api.my-domain.com/node_modules/express-handlebars/lib/express-handlebars.js:342:17)
at ExpressHandlebars.<anonymous> (/var/www/api.my-domain.com/node_modules/express-handlebars/lib/express-handlebars.js:223:35)
Run Code Online (Sandbox Code Playgroud)
这是我用于构建应用程序的 package.json 脚本:
"build": "tsc && babel ./lib --out-dir ./dist ",
Run Code Online (Sandbox Code Playgroud)
我如何更改它,以便删除当前内容,dist/email_templates然后将内容复制src/email_templates到dist/email_templates?
我有一个函数的类型定义。我将第二个参数的类型定义为以第一个参数的类型为条件,如下所示:
const FOO = "FOO";
const BAR = "BAR";
let fooPayload = {
zip: "zap"
}
let barPayload = {
cat: "dog"
}
type ActionTypes = typeof FOO | typeof BAR;
interface MyFunction<T extends ActionTypes = ActionTypes> {
(
action: {
type: T;
payload: T extends typeof FOO
? typeof fooPayload
: typeof barPayload;
}
): boolean;
}
Run Code Online (Sandbox Code Playgroud)
MyFunctioninterface 所引用的函数在其中包含一个 switch 语句,该语句基于 进行切换,action.type并根据情况对action.payload. 下面是一个例子:
const myFunction:MyFunction = (action) => {
switch (action.type) {
case FOO: …Run Code Online (Sandbox Code Playgroud) 我对如何设置配置文件以及我应该使用哪些配置/插件感到非常困惑。
我有一个使用 Typescript、Jest 和 React 钩子的 React 项目。
我知道我需要安装:
eslintprettier, eslint-config-prettier,eslint-plugin-prettiereslint-plugin-import至于Airbnb的配置,我不确定是否需要安装:
eslint-config-airbnb, eslint-plugin-react,eslint-plugin-jsx-a11y
或eslint-config-airbnb-base这些似乎都不支持Typescript,所以我似乎还需要安装:
@typescript-eslint/eslint-plugin, @typescript-eslint/parser对于 Jest,我需要安装:
eslint-plugin-jest我不确定 React 钩子。我是否需要在此处安装任何其他内容,或者其他软件包之一是否包含对它的支持?我看到我可以选择安装:
eslint-plugin-react-hooks这是必须的吗?
现在,对于配置文件,我关心两个方面:extends和plugins.
我看到其中一些包可以用/recommended. 我应该使用这些吗?该extends部分应该是什么?我见过将其设置为的示例:
{
"extends": ["airbnb-base", "plugin:prettier/recommended"]
}
Run Code Online (Sandbox Code Playgroud)
虽然我已经看到其他使用的例子:
{
"extends": ["airbnb", "prettier"]
}
Run Code Online (Sandbox Code Playgroud)
另一个使用示例:
{
"extends": [
"airbnb",
"plugin:prettier/recommended",
"prettier/react"
]
}
Run Code Online (Sandbox Code Playgroud)
其他 Typescript、Jest 和 React Hooks 插件怎么样?例如,eslint-plugin-jest建议添加"plugin:jest/recommended"到扩展中。这会与其他任何人发生冲突吗?我看到我也可以添加"plugin:@typescript-eslint/recommended"和"prettier/@typescript-eslint" …
typescript ×3
jestjs ×2
babeljs ×1
eslint ×1
eslintrc ×1
material-ui ×1
node.js ×1
npm-scripts ×1
prettier ×1
sip ×1
twilio ×1
twilio-api ×1
voip ×1