我似乎无法解决为什么收到此错误:这是我的配置:
lang-js
react - 15.3.1
react-dom - 15.3.1
react-testing-library - 6.0.0
jest - 23.6.0
lang-js
import React from 'react';
import { render, fireEvent, cleanup } from 'react-testing-library';
afterEach(cleanup);
test('loads and displays ', async() => {
})
Run Code Online (Sandbox Code Playgroud)
我在页面上评论了一个未解决的GH 问题react-testing-library。提前致谢
我正在使用 AJV 库来验证我的 JSON 模式。我希望能够验证Startdate为字符串。如果它不是字符串,则应将其转换为N/A. 目前,它仅转换undefined为N/A.
但是,在这些情况下,它不会按预期工作:
null -> "空"如果我想将上述所有内容转换为N/A字符串,我的 customKeyword 函数会是什么样子?
JSON 响应:
jsonResponse: {
"Issue": {
"StartDate": "December 17, 1995 03:24:00"
}
}
Run Code Online (Sandbox Code Playgroud)
架构:
var ajv = new Ajv({
useDefaults: true,
coerceTypes: 'undefined'
});
const schema = {
"type": "object",
"properties": {
"Issue": {
"type": "object",
"properties": {
"StartDate": {
"type": "string"
"default": "N/A",
"stringTypeChecker"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
添加关键字函数: …
我正在尝试渲染不带键的JSX的react组件数组。问题不幸的是,当我尝试在数组中设置键时,我遇到了JS错误:
Uncaught (in promise) TypeError: Cannot assign to read only property 'key' of object '#<Object>'
Run Code Online (Sandbox Code Playgroud)
这是代码:
import React, { Component } from 'react';
class Test extends Component {
mapChildObjects = () => {
const { children } = this.props;
let arr = [];
for (let i = 0; i < children.length; i++) {
arr.push(React.createElement(children[i]));
arr[i].key = i;
}
return arr;
}
render() {
return (
<div>
<div className={s.content}>
{this.mapChildObjects()}
</div>
</div>
);
}
}
export default Test
Run Code Online (Sandbox Code Playgroud)
阅读文档后:https : …
这是我的代码.我能够显示数字1-100,但我无法弄清楚如何操纵代码跳过不是3的倍数的数字.我有一种感觉,我必须使用逻辑运算符.
for ( var i = 1 ; i < 100 ; i++ ){
document.write(i + "<br>");
if ( i == 100) {
break;
}
}
Run Code Online (Sandbox Code Playgroud) javascript ×4
reactjs ×2
ajv ×1
jestjs ×1
json ×1
jsonschema ×1
loops ×1
types ×1
validation ×1
variables ×1