如何在玩笑的单元测试中测试Bootstrap Vue组件的存在?
所以我有一些包含b-form-input
组件的代码,我正在测试该组件是否呈现.我正在使用wrapper.find({name: "b-form-input"}).exists()
来确定该引导vue组件是否存在.但是,当我知道组件正在渲染时,此函数将连续返回false.关于如何正确执行此操作,我可以帮些忙吗?
So I have some code that has a b-form-input
component and I am testing whether that component renders. I am using wrapper.find({name: "b-form-input"}).exists()
to determine whether that bootstrap vue component exists. However this function continually returns false when I know that the component is rendering. Could I have some help on how to do this correctly?
查看bootstrap-vue
源代码,看起来该元素的名称是BFormInput
而不是b-form-input
(它是使用kebab-情况):
Looking at the bootstrap-vue
source code, it looks like the name of the element is BFormInput
and not b-form-input
(it was registered using kebab-case):
...
export const BFormInput = /*#__PURE__*/ Vue.extend({
name: 'BFormInput',
...
有两个选项可以找到组件;使用名称或组件构造函数.例如:
You have two options to locate the component; using the name, or the component constructor. For example:
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);
});
});