javascript - 如何使用 Cypress 和 Vue 中的组件进行组件测试?

标签 javascript vue.js testing cypress

我需要使用 Vue 将 Cypress 组件测试导入插槽中的组件。

文档说对于插槽:

import DefaultSlot from './DefaultSlot.vue'

describe('<DefaultSlot />', () => {
  it('renders', () => {
    cy.mount(DefaultSlot, {
      slots: {
        default: 'Hello there!',
      },
    })
    cy.get('div.content').should('have.text', 'Hello there!')
  })
})

我想这样做:

<DefaultSlot>
 <AnotherSlot />
</DefaultSlot>

最佳答案

为了解决我的问题,我使用以下组件选项导入了组件:

import DefaultSlot from './DefaultSlot.vue'
import AnotherSlot from './AnotherSlot.vue'

describe('<DefaultSlot />', () => {
  it('renders', () => {
    cy.mount(DefaultSlot, {
      components: {
        AnotherSlot
      }
      slots: {
        default: '<AnotherSlot label="my label" />',
      },
    })
    cy.get('div.content').should('have.text', 'Hello there!')
  })
})

关于javascript - 如何使用 Cypress 和 Vue 中的组件进行组件测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75359696/

相关文章:

javascript - 获取从今天开始的星期几

javascript - 使用 Javascript 获取自定义 HTTP header

vue.js - Vue : initial triggering of a computed property

javascript - 如何从闭包范围动态访问局部变量(通过其名称的字符串形式)?

javascript - 为什么我要在常规 Web 应用程序中使用输入类型日期?

javascript - 使用vue加载本 map 片时出现404错误

javascript - 是什么原因导致此 Vue 计算器应用程序中的模板变量更新失败?

html - 如何确定 <a> 是否被禁用

java - 这是集成测试还是单元测试?

python - Selenium 更改语言浏览器 Chrome/Firefox