Jos*_*ery 2 vue.js jestjs vue-component vuejs2 bootstrap-vue
所以我有一些包含b-form-input
组件的代码,我正在测试该组件是否呈现。我正在使用wrapper.find({name: "b-form-input"}).exists()
来确定该 bootstrap vue 组件是否存在。但是,当我知道组件正在渲染时,此函数会不断返回 false。我可以就如何正确执行此操作提供一些帮助吗?
查看bootstrap-vue
源代码,看起来元素的名称是BFormInput
和不是b-form-input
(它是使用 kebab-case 注册的):
Run Code Online (Sandbox Code Playgroud)... export const BFormInput = /*#__PURE__*/ Vue.extend({ name: 'BFormInput', ...
您有两种选择来定位组件;使用名称或组件构造函数。例如:
import BootstrapVue, { BFormInput } from 'bootstrap-vue';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import HelloWorld from '@/components/HelloWorld.vue';
const localVue = createLocalVue();
localVue.use(BootstrapVue);
describe('HelloWorld.vue', () => {
it('BFormInput exists', () => {
const wrapper = shallowMount(HelloWorld, { localVue })
expect(wrapper.find({ name: 'BFormInput' }).exists()).toBe(true);
expect(wrapper.find(BFormInput).exists()).toBe(true);
});
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1908 次 |
最近记录: |