在使用Cy.Intercep的同一端点与Cypress JavaScript一起使用CY.INTERCEP时,如何在夹具文件夹中制作多个.json文件
在这一点上,我将API端点与柏树截距固定。 它运行良好,但是我感觉可以更有效地使用它。
目前,我有以下测试:
cy.intercept('GET', '**/Classifications', { fixture: 'stubClassifications/Classifications5.json' })
cy.get('div.dropdown-menu.show').find('a.dropdown-item').should('have.length', 5)
正在工作,并检查文件分类。
它
classification5.json:json:
[
{
"id": "6a75b703-8af4-4734-8d3f-c259d36b7a5e",
"name": "1STUBTest EEO",
"hasChildren": false
},
{
"id": "6a75b703-8af4-4734-8d3f-c259d36b7a5e",
"name": "2STUBTest EEO",
"hasChildren": false
},
{
"id": "6a75b703-8af4-4734-8d3f-c259d36b7a5e",
"name": "3STUBTest EEO",
"hasChildren": false
},
{
"id": "6a75b703-8af4-4734-8d3f-c259d36b7a5e",
"name": "4STUBTest EEO",
"hasChildren": false
},
{
"id": "6a75b703-8af4-4734-8d3f-c259d36b7a5e",
"name": "5STUBTest EEO",
"hasChildren": false
}
]
在以下测试中,我正在固定相同的api-endpoint,但与只有1个分类,即分类1.json。
如您所见,我在固定图中制作了几个.JSON文件,每次我断言的结果,这看起来不太好且干净。
在使用CY.Intercept的同一终点时,我如何防止在地图固定装置中制作多个.json文件。
At this point I am stubbing API endpoints with Cypress Intercept.
It is working great, but I've the feeling I could use it more efficient.
Currently I have the following test:
cy.intercept('GET', '**/Classifications', { fixture: 'stubClassifications/Classifications5.json' })
cy.get('div.dropdown-menu.show').find('a.dropdown-item').should('have.length', 5)
It's working, and checks the file Classifications5.json where 5 classifications are available.:
Classifications5.json:
[
{
"id": "6a75b703-8af4-4734-8d3f-c259d36b7a5e",
"name": "1STUBTest EEO",
"hasChildren": false
},
{
"id": "6a75b703-8af4-4734-8d3f-c259d36b7a5e",
"name": "2STUBTest EEO",
"hasChildren": false
},
{
"id": "6a75b703-8af4-4734-8d3f-c259d36b7a5e",
"name": "3STUBTest EEO",
"hasChildren": false
},
{
"id": "6a75b703-8af4-4734-8d3f-c259d36b7a5e",
"name": "4STUBTest EEO",
"hasChildren": false
},
{
"id": "6a75b703-8af4-4734-8d3f-c259d36b7a5e",
"name": "5STUBTest EEO",
"hasChildren": false
}
]
In a following test I am stubbing the same API-endpoint but with just 1 classification, namely Classifications1.json.
As you can understand I made several .json file in the fixture map for each result that I am asserting and this doesn't look very nice and clean.
How can I prevent making multiple .json files in the map fixtures when using the cy.intercept for the same end-point.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您在说
classifation1.json
是classification5.json
的较小版本?如果是这样,您只需要
classification5.json
文件。可以从中得出较小的文件。在两项测试
生成固定装置
中,如果更改的唯一变化是
name
属性,则可以即时生成固定装置。It seems like you are saying that
Classifications1.json
is a smaller version ofClassifications5.json
?If so you only need the
Classifications5.json
file. Smaller files can be derived from it.In a two-item test
Generating the fixture
If the only thing that changes is the
name
property, you could generate the fixture on the fly.