在我的应用程序中,我使用 React 和 TypeScript。我尝试运行 Jest 测试,但出现以下错误:
Run Code Online (Sandbox Code Playgroud)C:\Users\e-KDKK\workspace\konrad\mikskarpety\src\images\icons\Sock.svg:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){<svg xmlns="http://www.w3.org/2000/svg" width="18.725" height="23.947" viewBox="0 0 18.725 23.947"> ^ SyntaxError: Unexpected token < 1 | import React, { FC } from 'react'; 2 | > 3 | import SockIcon from '../../images/icons/Sock.svg'; | ^ 4 | 5 | export const Spinner: FC = () => { 6 | return ( at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17) at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25) at Object.<anonymous> (src/components/Spinner/Spinner.tsx:3:1)
这个文件甚至没有经过测试。我不知道为什么它试图编译它。我的jest.config.json文件只包含覆盖阈值。
我读到 jest 有时需要针对特定文件(如 SVG)进行额外的转换部分,但是当我添加到配置时
"transform": {
"^.+\\.svg$": "jest-svg-transformer"
},
Run Code Online (Sandbox Code Playgroud)
我的错误信息仅更改为:
C:\Users\e-KDKK\workspace\konrad\mikskarpety\test\utils\debounce.test.ts:1 ({"Object.":function(module,exports,require,__dirname,__filename,global,jest){导入 …
我使用 react-bootstrap 库(https://react-bootstrap.github.io/components.html#tooltips),我想连续显示多个 div,每个 div 都有一个工具提示。
{ _.map(blueprint.components, (component, i) => {
const tooltipId = 'tooltip-' + _.replace(blueprint.name, ' ', '-') + '-' + _.replace(component.name, ' ', '-');
const tooltip = (
<Tooltip id={ tooltipId }>
test
</Tooltip>
);
return (
<div>
<OverlayTrigger key={ i } placement='top' overlay={ tooltip }>
<div>
<ImageIcon name={ component.name } size='small'/>
</div>
</OverlayTrigger>
</div>
);
}) }
Run Code Online (Sandbox Code Playgroud)
这是我为实现这一目标而编写的一段代码。示例蓝图对象如下所示:
[
{
"id": "123442b4d432d10008c650f7",
"name": "Example Blueprint",
"components": [
{
"name": "Apache",
"module": "apache",
"version": …Run Code Online (Sandbox Code Playgroud) javascript tooltip twitter-bootstrap reactjs react-bootstrap
我的联合体类型出现问题,如下所示:
type RepeatForm = {
step:
| {
repeat: false;
}
| {
repeat: true;
from: undefined;
}
| {
repeat: true;
from: string;
by?: string;
};
};
Run Code Online (Sandbox Code Playgroud)
我有以下函数,希望在那里获得价值by:
export const getByField = (form: RepeatForm) => {
if (form.step.repeat === false || form.step.from === undefined) {
return null;
}
const x = form.step.from;
return form.step.by;
};
Run Code Online (Sandbox Code Playgroud)
我收到此错误: Property 'by' does not exist on type '{ repeat: true; from: undefined; } | { repeat: true; from: string; by?: string …
我正在使用Angular Material,我使用$ mdDialogProvide创建了一个简单的预设对话框:
angular.module('starterApp').config([
'$mdDialogProvider',
function ($mdDialogProvider) {
$mdDialogProvider.addPreset('warning', {
options: function () {
return {
template:
'<md-dialog>' +
'{{dialog.warning}}' +
'</md-dialog>',
controllerAs: 'dialog',
theme: 'warning'
};
}
});
}
]);
Run Code Online (Sandbox Code Playgroud)
我想在调用它时传递一条警告信息.我试图传递一条消息,例如:
$mdDialog.show(
$mdDialog.warning({
locals: {
warning: 'Warning message'
}
})
);
Run Code Online (Sandbox Code Playgroud)
但是不起作用.
实际上我检查了很多解决方案,但没有一个能正常工作.文档中也没有这样的例子.
是否可以将某些日期传递给预设对话框?
我有 Windows 10 家庭版,因此我必须安装 Docker Toolbox 而不是 Docker。我正在使用 Visual Studio Code 进行开发,它具有 Docker 支持的扩展 ( https://github.com/Microsoft/vscode-docker ),它为最常见的 Docker 命令添加了集成。
不幸的是,它在我的情况下不起作用(来自 Visual Studio Code 终端的输出):
C:\Users\Konrad\workspace\docker-tests>docker build . -t docker-whale
An error occurred trying to connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/build?buildargs=%7B%7D&cgr
oupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory
=0&memswap=0&rm=1&shmsize=0&t=docker-whale&ulimits=null: open //./pipe/docker_engine: The system cannot find the
file specified.
Run Code Online (Sandbox Code Playgroud)
相同的命令在 Docker 快速入门终端中运行良好。
是否可以像“Docker Quickstart Terminal”一样将 Visual Studio Code 配置为使用 docker?我应该更改一些系统配置才能使用它吗?
你好,我想为这样的对象创建一个类型:
const z = {
name: { // this one is special
buty: ['qqqq']
},
lipa: ['xxx'],
// more keys here
};
Run Code Online (Sandbox Code Playgroud)
Bacially 它是这样的对象
type Test = {
[key: string]: string[]
}
Run Code Online (Sandbox Code Playgroud)
除了一个小例外。它总是有一个值略有不同的键名。
type Special = {
name: {
[key: string]: string[]
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试合并这两种类型时
type Test =
{ [key: string]: string[] } &
{ name: { [key: string]: string[] } };
const z: Test = {
name: { // this one is special
buty: ['qqqq']
},
lipa: ['xxx'],
// …Run Code Online (Sandbox Code Playgroud) 我有一个使用axios get方法的函数,并且在承诺返回时我添加了错误处理来处理我尝试连接的服务已被禁用的情况.
axios.get('/someurl')
.then(() => {
// this does not matter
})
.catch((err) => {
logger.error(TAG, 'postCreateVm', err);
return reply(Boom.forbidden(err.message));
});
Run Code Online (Sandbox Code Playgroud)
当我使用curl时,我可以看到消息,响应状态为403:
# curl -X GET localhost:3000/someurl
{
"message": "abort"
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试访问"消息"属性时我什么也得不到,但我知道它就在那里!(我也试过使用err.response.data也没有成功)
根据文档我应该能够访问它:axios处理错误
访问此消息的正确方法是什么?
javascript ×3
reactjs ×2
typescript ×2
angularjs ×1
axios ×1
dialog ×1
docker ×1
jestjs ×1
node.js ×1
svg ×1
tooltip ×1
types ×1
union-types ×1
windows-10 ×1