当我使用postman发送POST请求到localhost:8080/api/newUser with request body:
{name: "Harry Potter"}
Run Code Online (Sandbox Code Playgroud)
在服务器端,console.log(req.body)打印:
{ '{name: "Harry Potter"}': '' }
Run Code Online (Sandbox Code Playgroud)
server.js
var express = require('express');
var app = express();
var router = express.Router();
var bodyParser = require('body-parser');
app.use('/', express.static(__dirname));
router.use(function(req, res, next) {
next();
});
router
.route('/newUser')
.post(function(req, res) {
console.log(req.body);
});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json()); // support json encoded bodies
app.use('/api', router);
app.listen(8080);
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在用 Cypress 编写一个端到端测试,我想存根我的应用程序发出的网络请求。具体来说,我想删除多个在正文中有参数的 POST 请求,并根据这些参数更改我的模拟响应。
我想做类似的事情
cy.route({
method: "POST",
url: "/todos/add"
params: {
"urgency": 3,
"stakeholder_id": "SKH001"
},
response: "fixture:add1.json",
})
cy.route({
method: "POST",
url: "/todos/add"
params: {
"urgency": 1,
},
response: "fixture:add2.json",
})
Run Code Online (Sandbox Code Playgroud)
但是在阅读 https://docs.cypress.io/guides/guides/network-requests.html和https://docs.cypress.io/api/commands/route.html#Arguments 后,我没有看到支持检查被存根的请求中的参数的方法。
我可以通过将函数传递给 的onRequest参数来完成此操作cy.route吗?如果是这样,我会从那个告诉赛普拉斯“这条路线实际上不处理这个请求”的函数返回什么?
在我的网站中,我有一个搜索,它以卡片格式输出结果,如下所示:
然而,当显示多个结果时,它们不会溢出到下一行,而是卡片保持在同一行并变得更薄,并且卡片内的内容看起来很难看。它变得更像这样:
。
div卡代码:
<div class="card">
<a href="#">
<div class="image">
<div class="title">
</div>
</div>
</a>
<div class="description">
<h5>Title</h5>
<p>Description</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
以及卡片 div 的 CSS(我认为图像和描述 div css 在这里并不重要):
.card
{
height:18em;
width:14em;
margin: 10px;
display: flex;
flex-wrap: wrap;
flex-direction:column;
position:relative;
border-radius:16px;
overflow:hidden;
box-shadow: 15px 15px 27px #e1e1e3, -15px -15px 27px #ffffff;
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,div 是flex对象,我已经添加了该flex-wrap: wrap属性,但它没有换行。我还尝试了其他解决方案,例如display: inlineordisplay: inline-block或float: left,但都不起作用(我从网上获得了所有这些解决方案,主要是 Stack Overflow,但由于它们不起作用,我不得不就这个问题发表另一篇文章)。
有人可以帮我解决这个问题吗?请记住,结果是通过搜索输出的,因此不可能通过例如换行等方式手动修复换行。
谢谢!
我有一个表,我想确保使用 Cypress 的列中不会重复值。目前,我正在做
cy.get("#myTable")
.find(".table")
.contains("unique_value")
.should("exist")
Run Code Online (Sandbox Code Playgroud)
这段代码确实检查列中的值是否存在,但它不能确保它是表中具有此值的唯一条目。如何通过 Cypress 检查唯一性?
cypress ×2
body-parser ×1
css ×1
display ×1
express ×1
flexbox ×1
javascript ×1
node.js ×1
stub ×1
testing ×1