带有组件测试的固定装置

发布于 2025-02-13 21:24:47 字数 399 浏览 1 评论 0原文

执行柏树组件测试,我将固定装置加载到钩子之前。

固定装置加载,但在第一次测试后消失。

before(() => {
  cy.fixture('my-fixture').as('fixture')
})

it('test1', function() {
  mount(component, {
    propsData: {'data': this.fixture},
  })
})

it('test2', function() {
  mount(component, {
    propsData: {'data': this.fixture},  // undefined
  })
})

如何修复固定装置?

Performing a Cypress component test, I load a fixture in a before hook.

The fixture loads, but disappears after the first test.

before(() => {
  cy.fixture('my-fixture').as('fixture')
})

it('test1', function() {
  mount(component, {
    propsData: {'data': this.fixture},
  })
})

it('test2', function() {
  mount(component, {
    propsData: {'data': this.fixture},  // undefined
  })
})

How do I fix the fixture?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失而复得 2025-02-20 21:24:47

在测试之间清除了Alises。您可以将钩子更改为tofEreach(),以允许所有测试查看数据。

请注意,每次称为磁盘时,都不会从磁盘中读取固定装置,cy.fixture()命令具有一个缓存。

beforeEach(() => {
  cy.fixture('my-fixture').as('fixture')
})

it('test1', function() {
  mount(component, {
    propsData: {'data': this.fixture},
  })
})

it('test2', function() {
  mount(component, {
    propsData: {'data': this.fixture},  // passes
  })
})

Alises are cleared down between tests. You can change the hook to beforeEach() to allow all tests to see the data.

Note that the fixture is not read from disk every time it's called, the cy.fixture() command has a cache the returns the previously read value on 2nd, 3rd calls.

beforeEach(() => {
  cy.fixture('my-fixture').as('fixture')
})

it('test1', function() {
  mount(component, {
    propsData: {'data': this.fixture},
  })
})

it('test2', function() {
  mount(component, {
    propsData: {'data': this.fixture},  // passes
  })
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文