VUE开玩笑单元测试,可以从组件库中进行测试或渲染组件
我们有一些复杂的形式,取决于登录方式,我们呈现不同的按钮。
但是,该组件来自通过NPM安装的库。因此,我在开玩笑时遇到困难。
有没有办法渲染 /加载组件以便我可以测试正确的组件?
describe('P1 buttons - show the correct buttons for credential type and registration status', () => {
beforeEach(async () => {
await wrapperBeforeEach();
});
test('expect button for OPEN_BANKING_UK_MANUAL to be visible', async () => {
currentRegistrationDetails.credentials = institutionP1UkAutoBarclays;
wrapper.vm.currentRegistrationDetails.platform = 'P1';
await wrapper.vm.$nextTick();
// wont work if Button is component
const button = wrapper.find('[data-test-id="button-p1-download-ssa"]');
// this would work if the Button component was local to the project
const buttomExternal = wrapper.findComponent(Button);
const registrationP1 = wrapper.find('.registration-p1');
console.log(registrationP1.html());
// this fails as Button doesn't render at all.
expect(buttomExternal.isVisible()).toBe(true);
});
});
来自console.log(registrationp1.html()))的HTML;
是这样 -
<div class="form-actions mb-5">
<div class="form-actions-content">
<!---->
<!---->
</div>
</div>
出现我们的应用程序中的按钮
<!---->
<!---->
在使用我们的组件库的同时,我们不断地
。实际按钮标记是
<Button
data-test-id="button-p1-download-ssa"
type="primary"
class="primary button"
:is-loading="savingSsa"
:on-click="downloadTheSsaFromModal"
>Request the SSA</Button
>
We have some complex forms and depending on the login we render different buttons.
However the component comes from a library installed via NPM. So I'm having trouble reaching them in Jest.
Is there a way to render / load the components so I can test the right ones are present?
describe('P1 buttons - show the correct buttons for credential type and registration status', () => {
beforeEach(async () => {
await wrapperBeforeEach();
});
test('expect button for OPEN_BANKING_UK_MANUAL to be visible', async () => {
currentRegistrationDetails.credentials = institutionP1UkAutoBarclays;
wrapper.vm.currentRegistrationDetails.platform = 'P1';
await wrapper.vm.$nextTick();
// wont work if Button is component
const button = wrapper.find('[data-test-id="button-p1-download-ssa"]');
// this would work if the Button component was local to the project
const buttomExternal = wrapper.findComponent(Button);
const registrationP1 = wrapper.find('.registration-p1');
console.log(registrationP1.html());
// this fails as Button doesn't render at all.
expect(buttomExternal.isVisible()).toBe(true);
});
});
The HTML from console.log(registrationP1.html());
is this —
<div class="form-actions mb-5">
<div class="form-actions-content">
<!---->
<!---->
</div>
</div>
The buttons should appear between the
<!---->
<!---->
We keep running into these issues with our applications whilst using our component library.
The actual button markup is
<Button
data-test-id="button-p1-download-ssa"
type="primary"
class="primary button"
:is-loading="savingSsa"
:on-click="downloadTheSsaFromModal"
>Request the SSA</Button
>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您只需要测试道具与
npm
依赖关系正确绑定。测试其他库中的按钮
不在您的范围中。I think you only have to test that the props are bound correctly with the
npm
dependency. It's not in your scope to test that theButton
from an other library is working.