Tsu*_*una 1 javascript unit-testing graphql graphql-js cypress
我在Google上搜索过类似内容,cypress request with graphql但我看到很多人都在谈论mock up server,stub等等。但是我无法找到完整的示例以及如何cypress.io与graphqlusing请求一起使用。
有谁知道它是如何cy.request工作的,graphql或者在哪里可以找到它的解决方案?
在此先感谢您的帮助。
也许你可以使用这个时候这个尝试cy.request非常喜欢使用通常的方式restful在cy.request
例如,您的查询名称findUser带有查询的变量,username
看起来应该像这样findUser(username:"hello"){id, name},依此类推
但是,您不仅需要传递它,还需要传递它,就json好像它是一个查询一样,{"query": findUser(username:"hello"){id, name}} 这实际上将是您的身体。
下面是一个例子...
const query = `{
findUser(username:"hello")
{
id
}
}`;
cy.request(
{
url: 'http://localhost/graphql/', // graphql endpoint
body: { query }, // or { query: query } depending if you are writing with es6
failOnStatusCode: false // not a must but in case the fail code is not 200 / 400
}
).then((res) => {
cy.log(res);
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1853 次 |
| 最近记录: |