Skip to content

Snap does not contain object content #891

@trollepierre

Description

@trollepierre
Contributor

Version

1.0.0-beta.22

Reproduction link

https://codesandbox.io/s/xr39rzv50z

Steps to reproduce

Have a child component passing a prop that is an array and generate snapshot

<child-component :myprop="{toto: 'toto', something: true}"/>

What is expected?

<childcomponent-stub
  myprop="{toto='toto', something: true}"
/>

What is actually happening?

<childcomponent-stub
  myprop="[object Object]"
/>

Activity

dcrystalj

dcrystalj commented on Jun 3, 2019

@dcrystalj

not sure but both tickets (this and linked) are closed, without resolution

TheJaredWilcurt

TheJaredWilcurt commented on Feb 19, 2020

@TheJaredWilcurt

@trollepierre @dcrystalj

There is an experimental feature in jest-serializer-vue-tjw that will allow for this:

You would need to enable the experimental feature in your vue.config.js.

module.exports = {
  pluginOptions: {
    jestSerializer: {
      stringifyObjects: true
    }
  }
};

With that enabled you can easily opt-in or out of the experimental feature on a per-snapshot basis:

test('Assuming stringifyObjects is enabled', () => {
  const wrapper = shallowMount(YourComponent);

  expect(wrapper)
    .toMatchSnapshot('This will stringify objects');

  expect(wrapper.html())
    .toMatchSnapshot('Use .html() to opt out of stringify objects');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dcrystalj@TheJaredWilcurt@trollepierre@eddyerburgh

        Issue actions

          Snap does not contain object content · Issue #891 · vuejs/vue-test-utils