Skip to content

shallowMount(Parent).contains(Child) returns false if Parent uses Child as a dynamic component (#853) #882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
caugner opened this issue Aug 1, 2018 · 3 comments

Comments

@caugner
Copy link

caugner commented Aug 1, 2018

Version

1.0.0-beta.23

Reproduction link

https://gitlab/mygroup/myproject

Steps to reproduce

Parent.spec.js

import { shallowMount } from "@vue/test-utils";
import { expect } from "chai";
import { Parent, Child } from "@/components";

describe("Parent.vue", function() {

  it("contains Child", () => {
    expect(shallowMount(Parent).contains(Child)).to.be.true;
  });
});

Parent.vue:

<template>
  <Child />
</template>

<script>
export default {
  components: {
    Child: () => import("@/components/Child")
  }
}
</script>

What is expected?

The tests should pass (like they did in 1.0.0-beta.20).

What is actually happening?

  1) Parent.vue
       contains Child:

      AssertionError: expected false to be true
        expected - actual

      -false
       true
@caugner caugner changed the title shallowMount(Parent).contains(Child) returns false if Parent uses Child asynchronously (#853) shallowMount(Parent).contains(Child) returns false if Parent uses Child as a dynamic component (#853) Aug 1, 2018
@caugner
Copy link
Author

caugner commented Aug 1, 2018

This is a follow-up of #853 (fixed in #864).

@eddyerburgh eddyerburgh added bug and removed bug labels Aug 4, 2018
@eddyerburgh
Copy link
Member

I believe this was working previously as a side effect of not being stubbed correctly. When we create the stubs, we don't have enough information to create a stub that can be identified with a component selector, like you have in your example.

You can acheive this functionality by using mount:

it('renders dynamic import', (done) => {
  const wrapper = mount(TestComponent)
  setTimeout(() => {
    expect(wrapper.find(Component).exists()).to.equal(true)
    done()
  })
})

Or by stubbing the component with the stubs option:

it('renders dynamic import', () => {
  const wrapper = mount(TestComponent, {
    AsyncComponent: Component
  })
  expect(wrapper.find(Component).exists()).to.equal(true)
})

Unfortunately, I don't think we'll be able to achieve the auto stubbing that you expected.

@caugner
Copy link
Author

caugner commented Aug 6, 2018

Thank you for the explanation, which totally makes sense, and the solutions. :-)

@caugner caugner closed this as completed Aug 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants