question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to test for elements within a transition

See original GitHub issue

Is there any way to test the rendering of an element that is contained in a transition?

<template>
  <transition name="fade" mode="out-in">
    <h1 v-if="showHeading">Herro<h1>
  </transition>
</template>


<script>
export default {
  data () {
    return {
      showHeading: false
    };
  }
};
</script>


<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity .5s
}
.fade-enter, .fade-leave-to {
  opacity: 0
}
</style>

The following test will fail on the above component unless I remove the transition.

it('renders an h1 when showHeading is true', () => {
  wrapper.setData({ showHeading: true });
  expect(wrapper.find('h1').length).to.equal(1);
});

Thanks a lot for avoriaz, by the way. I’ve been using it for the past couple days, and I love it.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jackyseecommented, Jun 30, 2017

Got it, have to use Vue.nextTick here.

  it('renders an h1 when show is true', (done) => {
    let wrapper = mount(Transition, { propsData: { show: true } });
    expect(wrapper.find('h1').length).to.equal(1);
    wrapper.setProps({ show: false });
    Vue.nextTick(() => {
      expect(wrapper.find('h1').length).to.equal(0);
      done();
    });
  });
1reaction
jackyseecommented, Jun 30, 2017

I’m using karma, but I cannot get the transition to work in unit test. Anything I miss?

vue file:

<template>
  <transition name="fade" mode="out-in">
    <h1 v-if="show">hello</h1>
  </transition>
</template>

<script>
export default {
  props: ['show']
};
</script>

<style>
.fade-enter-active, .fade-leave-active { transition: opacity .5s }
.fade-enter, .fade-leave-to { opacity: 0 }
</style>

Test

  it('renders an h1 when show is true', () => {
    let wrapper = mount(Transition, { propsData: { show: true } });
    expect(wrapper.find('h1').length).to.equal(1);
    wrapper.setProps({ show: false });
    expect(wrapper.find('h1').length).to.equal(0);
  });

Here the 2nd expect would fail.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test yourself on the transition element reactions - YouTube
Quick video to test yourself on the equations for the reactions of transition elements. Video covers all reactions required for the OCR A ......
Read more >
testing transition metal ions with sodium hydroxide solution
Practical skills assessment video - making butyl ethanoate video 1 : heating under reflux. Royal Society Of Chemistry.
Read more >
Testing for positive ions - transition metals ions - YouTube
Testing for positive ions - transition metals ionsSee CLEAPSS PP100 for more ... North Carolina School of Science and Mathematics.
Read more >
Test Yourself A Level Chemistry - Transition Elements 1
Link to questions https://drive.google.com/file/d/19T2SpfdgzxC37MbvDtuSF1qlhP6SEhrd/view?usp=sharing.
Read more >
Qualitative tests on First Row Transition Metal Ions
This is best done in a series of test tubes using small samples (1 or 2 mg or the amount needed to cover...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found