【发布时间】:2021-05-31 14:54:19
【问题描述】:
我想知道是否有办法使用 Cypress 发送 GraphQL 突变?
有cy.intercept(),但这更多是为了等待回复。
我的知识有限,所以我寻求帮助。
谢谢。
【问题讨论】:
我想知道是否有办法使用 Cypress 发送 GraphQL 突变?
有cy.intercept(),但这更多是为了等待回复。
我的知识有限,所以我寻求帮助。
谢谢。
【问题讨论】:
您可以使用cy.request(),您只需要知道 GraphQL 的工作原理以及您需要发送到端点的有效负载的格式。
一个例子可以是:
describe('GraphQl example', () => {
it('Send req to graphql endpoint', () => {
const query = `{
speakers(name: "Miloš") {
id
firstName
lastName
}
}`;
cy
.request({
url: 'https://demagog.cz/graphql',
method: 'POST',
body: { query }
})
.then(res => {
cy
.log(res);
});
});
});
而且我很容易通过数据获得成功的响应:
你需要知道的事情:
cy.request()
【讨论】: