All files / tests/client utils.js

90% Statements 18/20
75% Branches 6/8
91.67% Functions 11/12
90% Lines 18/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35    3x   3x   3x   3x 3x     19x 19x 19x     19x             19x 19x 19x           19x 19x 19x
const Vue = require('vue');
const Html2jade = require('html2jade');
 
/** convert html to pug as a Promise */
function html2pug(html) {
  return new Promise((resolve, reject) => {
    Html2jade.convertHtml(html, {bodyless: true}, (err, jade) => {
      if (err) {
        reject(err)
      } else {
        resolve(jade)
      }
    })
  })
}I

/** call vm.nextTick() as a Promise */
function nextTick(vm) {
  return new Promise((resolve, reject) => {
    Vue.nextTick(() => resolve())
  })
}
 
/** call vm.nextTick() and check the snapshot as a Promise */
function expectToMatchSnapshot(vm, element) {
  return new Promise((resolve, reject) => {
    nextTick(vm).then(() => html2pug((element || vm.$el).innerHTML)).then((jade) => {
      expect(jade).toMatchSnapshot()
      resolve()
    }).catch((err)=>(reject(err)))
  })
}
 
exports.expectToMatchSnapshot = expectToMatchSnapshot;