【问题标题】:Vue.js and Jest - Element-UI how to programmatically confirm MessageBox?Vue.js 和 Jest - Element-UI 如何以编程方式确认 MessageBox?
【发布时间】:2020-07-06 17:46:39
【问题描述】:

我目前正在使用 Jest 创建测试,我想知道如何以编程方式确认 ElementUI 的 MessageBox,因为我似乎无法获得它的 HTML DOM。这样它就会在then() 中执行我的graphql 查询。我真的不知道这是否是一个好习惯,因为我是 Jest 的新手。

confirmBox(
        this,
        'warning',
        'Delete Record',
        'Do you really want to delete this record?',
        true
      ).then(() => {
        this.loading = true

        deleteGame(id, (response, success) => {
          if (success) {
            this.$message({
              message: 'Record successfully deleted',
              type: 'success'
            })
            this.get()
          } else {
            this.$message({
              message: response,
              dangerouslyUseHTMLString: true,
              type: 'error'
            })
            this.loading = false
          }
        })
      })

【问题讨论】:

    标签: javascript vue.js jestjs element-ui


    【解决方案1】:

    Element-ui 对所有组件都有单元测试,但是它们是用 karma 编写的。

    他们似乎触发了确定按钮如下:

    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

    【讨论】:

      猜你喜欢
      • 2017-12-01
      • 1970-01-01
      • 2013-05-23
      • 1970-01-01
      • 2018-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多