JSFiddle - React, Tailwind, and code Playground
HTML
<div id="app"></div>
JavaScript
new Vue({
el: '#app',
template: `
<span>
<button @click="test()">Run test</button>
<transition>
<p v-show="show">Hello, world!</p>
</transition>
</span>
`,
data() {
return {
show: false,
};
},
methods: {
test() {
const wait10 = _ => new Promise(resolve => setTimeout(resolve, 10));
const wait100 = _ => new Promise(resolve => setTimeout(resolve, 100));
const showParagraph = _ => this.show = true;
const hideParagraph = _ => this.show = false;
const p = document.querySelector('p');
showParagraph();
this.$nextTick()
.then(wait10)
.then(() => {
const display = getComputedStyle(p).display;
assertEqual(display, 'block');
})
.then(hideParagraph)
.then(this.$nextTick)
.then(wait100)
.then(() => {
const display = getComputedStyle(p).display;
assertEqual(display, 'none');
});
}
}
});
function assertEqual(a, b) {
if (a !== b) {
console.error('Expected "' + a + '" to equal "' + b + '"');
}
};