我目前正在使用Jest创建测试,我想知道如何以编程方式确认ElementUI的MessageBox,因为我似乎无法获取它的HTML DOM。这样它将在.cpp
内执行我的graphql查询。我真的不知道这是否是个好习惯,因为我是Jest的新手。
then()
答案 0 :(得分:0)
Element-ui对所有组件进行了单元测试,但是它们都是用业力编写的。
他们似乎触发了“确定”按钮,如下所示:
it('confirm', done => {
MessageBox.confirm('This is a piece of content', {
title: 'Title name',
type: 'warning'
});
setTimeout(() => {
document.querySelector('.el-message-box__wrapper')
.querySelector('.el-button--primary').click();
expect(document.querySelector('.el-message-box__wrapper')
.__vue__.$parent.visible).to.false;
done();
}, 200);
});
完整来源:https://github.com/ElemeFE/element/blob/dev/test/unit/specs/message-box.spec.js