Skip to content
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

fix(stubs): Do not render function body in stub #1819

Merged
merged 1 commit into from Oct 16, 2022

Conversation

xanf
Copy link
Collaborator

@xanf xanf commented Oct 15, 2022

@vue/test-utils v1 had special handing for functions in props when rendering stubs.

This PR makes @vue/test-utils v2 behave in the same way, even reusing same placeholder from https://github.com/vuejs/vue-test-utils/blob/97fdf18cd96f2ce19036d497ec98f2f76fc7b066/packages/create-instance/create-component-stubs.js#L21

(this allows us to run snaphot tests of vue2 and @vue/compat and to verify snapshots identity)

@netlify
Copy link

netlify bot commented Oct 15, 2022

Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit 0c68b20
🔍 Latest deploy log https://app.netlify.com/sites/vue-test-utils-docs/deploys/634aa457db273c000a465df5
😎 Deploy Preview https://deploy-preview-1819--vue-test-utils-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@freakzlike
Copy link
Collaborator

I think this will break using a function with .props().

const someFunction = wrapper.props('someFunction')
someFunction()

Maybe we can implement this logic into the wrapper.html() method?

@xanf
Copy link
Collaborator Author

xanf commented Oct 16, 2022

I think this will break using a function with .props().

@freakzlike I don't think so

image

Code for copy-paste
  it('does not have problems on stubbing functions', () => {
    const ChildCmp = { template: '<div>child</div>', props: ['fn'] }
    const Root = {
      components: {
        ChildCmp
      },
      props: ['fn'],
      template: '<child-cmp :fn="fn">'
    }

    const fn = vi.fn()
    const wrapper = shallowMount(Root, { props: { fn } })
    expect(wrapper.findComponent(ChildCmp).props('fn')).toBe(fn)
    expect(wrapper.findComponent(ChildCmp).html()).toBe(
      '<child-cmp-stub fn="[Function]"></child-cmp-stub>'
    )
  })

When we're retrieving props - we are getting them on stub component. It get's replaced only for rendering child dom element

@freakzlike
Copy link
Collaborator

Well, then LGTM 👍

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

Successfully merging this pull request may close these issues.

None yet

3 participants