当在代码中Jest.js
遇到时,我得到一个错误:import.meta
FAIL testFile.test.ts\n \xe2\x97\x8f Test suite failed to run\n\n testFile.ts:40:10 - error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.\n\n 40 return import.meta?.env as EnvironmentalVariablesType\n
Run Code Online (Sandbox Code Playgroud)\n我已经安装了以下 babel 相关包:
\n// package.json\n "devDependencies": {\n "@babel/core": "^7.16.5",\n "@babel/preset-env": "^7.16.5",\n "@babel/preset-typescript": "^7.16.5",\n "@vitejs/plugin-react-refresh": "1.3.6",\n "babel-jest": "^27.4.5",\n "jest": "27.3.1",\n "jest-environment-jsdom-global": "3.0.0",\n "react": "17.0.1",\n "ts-jest": "27.0.7",\n "typescript": "4.1.3",\n "vite": "2.6.14"\n "dependencies": {\n "babel-plugin-transform-vite-meta-env": "^1.0.3",\n "babel-preset-vite": "^1.0.4",\n
Run Code Online (Sandbox Code Playgroud)\n我设置babel.config.js
如下:
module.exports …
Run Code Online (Sandbox Code Playgroud) 我在 Phpstorm 2019.3 中看到了这个,在 .send() 下有一个红色的棉绒
// package.json
"dependencies": {
"express": "^4.17.1"
},
"devDependencies": {
"@types/express": "^4.17.2",
"tslint": "^5.12.0",
"typescript": "^3.2.2"
},
// index.ts
const express = require("express")();
express.get('/', (req: Request, res: Response): void => {
res.send('Express App Running') // TS2339: Property 'send' does not exist on type 'Response'
});
Run Code Online (Sandbox Code Playgroud)
这些是错误的类型定义还是其他什么东西在起作用?
当运行下面的小html文件时,我看到以下控制台日志错误:
moment.js:13 Uncaught TypeError: Cannot read property 'defineLocale' of undefined
at moment.js:13
at moment.js:9
at moment.js:10
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="../scripts/libraries/moment.js"></script>
</head>
<body>
<script>
var now = moment()
console.log(now);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我也尝试用这个CDN链接替换对本地库的引用: https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/af.js
有谁知道这个错误是什么?
grpc
即使我test()
在超时之前将我的笑话异步功能设置为 100000 毫秒上限,也无法连接。
// terminal, after running jest --watch
? creates new record
14 UNAVAILABLE: failed to connect to all addresses
at Object.<anonymous>.exports.createStatusError (node_modules/grpc/src/common.js:91:15)
at Object.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:1209:28)
at InterceptingListener.Object.<anonymous>.InterceptingListener._callNext (node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.Object.<anonymous>.InterceptingListener.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:618:8)
at callback (node_modules/grpc/src/client_interceptors.js:847:24)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 skipped, 2 total
Snapshots: 0 total
Time: 106.03s, estimated 116s
Ran all test suites related to changed files.
Watch Usage: Press w to show more.
owner@G700:~/PhpstormProjects/shopify/bu
FAIL functions/src/classes/__tests__/FirestoreConnection.test.ts (108.991s)
? creates …
Run Code Online (Sandbox Code Playgroud) 我将子组件从条件渲染切换到被包装,<Fade />
但是 Fade 根本不起作用,两个组件总是显示。这是当前的代码:
// inside top level component
{/*{adminView === bodyViews.addNewCoupon &&*/}
<Fade
in={Boolean(adminView === bodyViews.addNewCoupon)}
timeout={2000}
>
<AddCouponForm />
</Fade>
{/*}*/}
{/*{adminView === bodyViews.viewCurrentCoupons &&*/}
<Fade
in={Boolean(adminView === bodyViews.viewCurrentCoupons)}
timeout={2000}
>
<ViewCoupons />
</Fade>
{/*}*/}
Run Code Online (Sandbox Code Playgroud)
基于此处的 api:https : //material-ui.com/api/fade/ 我相信in
设置为 true 应该会导致组件淡入。这有助于在注释掉的一元中导致条件渲染,但似乎没有在in
价值范围内工作。正在犯什么错误?
更新
当我评论自定义组件并插入类似的东西时<p>Section 1/2</p>
,淡入淡出工作。关于自定义组件的某些事情必须导致淡入淡出不起作用
我收到此 PHP 错误:
PHP 警告:setcookie() 期望参数 3 为整数,给定数组
使用此代码:
$setResult = setcookie(
'visitorId',
"{$newIdForNewVisitor}",
[
'httponly' => true,
'expires' => time() + (50 * 365 * 24 * 60 * 60)
]
);
Run Code Online (Sandbox Code Playgroud)
但上的第二示例的setcookie
文档,我看到,参数3的选项参数可以关联数组:
一个关联数组,其中可能包含任何密钥 expires、path、domain、secure、httponly 和 samesite。这些值的含义与对同名参数描述的含义相同。samesite 元素的值应该是 Lax 或 Strict。如果没有给出任何允许的选项,它们的默认值与显式参数的默认值相同。如果省略 samesite 元素,则不会设置 SameSite cookie 属性。
这里犯了什么错误?
样式可能会出现 50 毫秒,然后在此 SSR 应用程序的以下代码中消失。我很好奇是什么原因造成的。
// This component is a child of index.tsx in the /pages folder
<Button
color="primary"
variant="outlined"
size="large"
>Test Button</Button>
Run Code Online (Sandbox Code Playgroud)
样式消失后,只剩下一个普通的 HTML 按钮。
我相信 Next.js 是造成这种情况的原因。我检查了 Next.js 文件并将 next/babel 加载器添加到 .babelrc。除此之外,我只看到了其他相关的变化。这是在 /pages/_document.js 中:
MyDocument.getInitialProps = async ctx => {
const sheets = new MuiServerStyleSheets();
const originalRenderPage = ctx.renderPage;
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: App => props => sheets.collect(<App {...props} />),
});
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
// Styles fragment is rendered after the …
Run Code Online (Sandbox Code Playgroud) jest-fetch-mock 有一个我遵循的 Typescript 设置指南:https ://www.npmjs.com/package/jest-fetch-mock
// package.json
, "devDependencies": {
"@types/jest": "^24.0.23",
"jest": "^24.9.0",
"jest-fetch-mock": "^2.1.2",
"ts-jest": "^24.2.0",
"typescript": "^3.7.2"
},
"jest": {
"automock": false,
"setupFiles": ["./setupJest.ts"]
}
// setupJest.ts
import {GlobalWithFetchMock} from "jest-fetch-mock";
const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;
customGlobal.fetch = require('jest-fetch-mock');
customGlobal.fetchMock = customGlobal.fetch;
Run Code Online (Sandbox Code Playgroud)
但是当我尝试设置一个虚拟的解析值时:
// ScriptTag.test.ts
test("", async () => {
fetch.mockResponseOnce(JSON.stringify(1));
const data = await fetchMock("x");
await expect(data.json()).resolves.toStrictEqual(2);
})
// terminal
FAIL functions/src/classes/__tests__/ScriptTag.test.ts
? Test suite failed to run
TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` …
Run Code Online (Sandbox Code Playgroud) 这是 Google Chrome 中新的 React Dev Tools 的屏幕截图:
仅显示顶级组件名称AdminArea
。这个组件在我脚本的入口文件中index.jsx
。还应该有 AddNewCoupon 和 ViewCoupons 组件。没有启用过滤器。
另请注意,组件内的状态挂钩命名仅表示“状态”。这些是展位 useState() 钩子。
可以看到 useReducer 的初始状态变量名称,但这只是因为我直接将该变量导出和导入到入口文件中index.jsx
。
有人知道如何解决这些标签问题吗?
VSCode 在提示中显示以下警报:
找不到 Node.js 二进制“节点”:路径不存在。确保 Node.js 已安装并在您的 PATH 中,或在您的 launch.json 中设置“runtimeExecutable”
在终端中,我看到节点的 NVM 路径:
$ node --version
v12.18.4
$ echo $PATH
/home/owner/.config/nvm/versions/node/v12.18.4/bin
:/usr/local/sbin:/usr/local/bin:/usr/sbin
:/usr/bin:/sbin:/bin:/usr/games
:/usr/local/games:/snap/bin
// line breaks manually added by me for readability
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic
$ npm --version
6.14.6
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个 PATH 问题?
我怀疑问题出在 PATH 而不是 VsCode,但我在下面包含了我的 launch.json 以防我错了。
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": …
Run Code Online (Sandbox Code Playgroud)