我尝试设置 jest、supertest 和 express,但失败了。我有这两个简单的文件
索引.js
const express = require("express");
const app = express();
const port = 3000;
app.get("/", (req, res) => res.send("Hello World!"));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
Run Code Online (Sandbox Code Playgroud)
和 index.test.js
const express = require("express");
const app = express();
const request = require("supertest");
describe("/", () => {
test("it says hello world", done => {
request(app)
.get("/")
.expect(200)
.end(function(err, res) {
console.log("err", err);
});
});
});
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,我收到此错误。
err Error: expected 200 "OK", got 404 "Not Found"
怎么了?
我在浏览器中访问 …
我有一个具有受控状态的下拉菜单。如果用户更改了下拉值并且输入不为空,则触发从其他组件传递的函数。
export default ({ triggerChange, inputVal }) => {
const [dropdown, setDropdown] = useState(1);
useEffect(() => {
if (inputVal) {
triggerChange(dropdown);
}
}, [dropdown]); // this line throw a warning
const handleChange = e => {
setDropdown(e.target.value);
};
return (
<div>
<select onChange={handleChange}>
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
);
};
Run Code Online (Sandbox Code Playgroud)
错误
React Hook useEffect 缺少依赖项:“inputVal”和“triggerChange”。包括它们或删除依赖项数组。如果 'triggerChange' 更改过于频繁,请找到定义它的父组件并将该定义包装在 useCallback 中。(反应钩子/详尽的deps)
let finalPrice = room.points[0].price.finalPrice //string
finalPrice = +finalPrice //number
finalPrice = finalPrice.toFixed(2) //2 decimal
Run Code Online (Sandbox Code Playgroud)
是否可以缩短上述类型的转换?
如果我做
+room.points[0].price.finalPrice.toFixed(2)
Run Code Online (Sandbox Code Playgroud)
我会收到此错误: toFixed is not a function