admin管理员组文章数量:1391999
let say I have this setting.json
{ data: { isDark: false } }
and I intercept it like so
cy.intercept("api/setting", {
fixture: `setting.json`,
})
it worked.
But there's no way I want to create one file for one new property in the setting.json or when isDark is true. So how can I change the property values of the setting.json in my test?
I tried
cy.intercept("api/setting", (req) => {
const settingFixture = await cy.fixture('setting.json')
req.continue((res) => {
res.send(settingFixture.map((object)=>({...object, isDark: true}))
})
cy.visit('some where')
})
but it doesn't work.
let say I have this setting.json
{ data: { isDark: false } }
and I intercept it like so
cy.intercept("api/setting", {
fixture: `setting.json`,
})
it worked.
But there's no way I want to create one file for one new property in the setting.json or when isDark is true. So how can I change the property values of the setting.json in my test?
I tried
cy.intercept("api/setting", (req) => {
const settingFixture = await cy.fixture('setting.json')
req.continue((res) => {
res.send(settingFixture.map((object)=>({...object, isDark: true}))
})
cy.visit('some where')
})
but it doesn't work.
Share Improve this question asked Jan 6, 2022 at 9:25 Alicia YAlicia Y 3871 gold badge6 silver badges16 bronze badges 1- I think part of your answer in this video youtube./watch?v=vlLLi5N4h78, check it out – Evgenii Bazhanov Commented Jan 6, 2022 at 9:50
1 Answer
Reset to default 8According to Cypress documentation about fixture mand (https://docs.cypress.io/api/mands/fixture#Modifying-fixture-data-before-using-it), I think you can try something like this:
cy.fixture('setting.json').then(settingFixture => {
// Update your JSON object according to your context
// ...
// Stub your response with this JSON object updated
cy.intercept("api/setting", settingFixture)
});
// Navigate to your URL
cy.visit('some where')
本文标签: javascriptmodify fixture data in cypress and intercept itStack Overflow
版权声明:本文标题:javascript - modify fixture data in cypress and intercept it - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744631336a2616558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论