我正在使用赛普拉斯组件测试。我目前有以下代码来设置我的一个组件测试套件,加载一次夹具(之前)然后每次安装它(beforeEach)
before(() => {
cy.fixture('entries/index').as('index').then( (index) => {
index.forEach( (item) => {
item.created_at = DateTime.fromISO(item.created_at)
})
})
})
beforeEach(function() {
mount(component, {
propsData: {'index':this.index},
})
})
这对于运行的第一个测试完全符合预期,但对于第二个测试失败,因为'this.index' 对于第二个测试变得未定义。通过转储输出,这发生在第一次测试完成后,而不是在组件安装时。
it("Does foo",() => {
cy.contains('foo')
})
it("Does bar", () => {
cy.contains('bar')
})
第一个测试有效,第二个测试组件安装了空数据。我究竟做错了什么?我可以将夹具从之前移动到 beforeEach,但是当它只需要执行一次时,夹具文件会被多次读取。