forked from SSENSE/vue-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
34 lines (30 loc) · 881 Bytes
/
utils.js
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
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)
}
})
})
}
/** 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;