jest-serializer-vue icon indicating copy to clipboard operation
jest-serializer-vue copied to clipboard

render objects

Open dcrystalj opened this issue 6 years ago • 3 comments

problem

passing object to prop of one component should be serialized

example

serializing following component:

<template>
<div>
 <custom-component :data="{a: true}">
</div>
</template>

gives you somehting like this:

exports[`InstantOrderForm snapshot renders 1`] = `
<div>
 <custom-component-stub data="[object Object]">
</div>

solution

can this be fixed? am I doing something wrong? I would like to keep data="{a: true}" in snapshot

dcrystalj avatar Jun 03 '19 13:06 dcrystalj

@dcrystalj This was a great request. It was also a huge pain in the ass to get to work. But here I am, 1am publishing to npm.

  • https://www.npmjs.com/package/jest-serializer-vue-tjw
// this will work
expect(wrapper)
  .toMatchSnapShot();

// this will not, the `[object Object]` is already in place
expect(wrapper.html())
  .toMatchSnapshot();

The feature is experimental, so create issues if you have problems with it. You will need to enable it in your vue.config.js file.

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

TheJaredWilcurt avatar Jan 16 '20 05:01 TheJaredWilcurt

+1 for this feature request, are there any plans to merge in @TheJaredWilcurt's work?

edfowle avatar Oct 11 '21 15:10 edfowle

I'm quite busy at the moment (my first son was born a few months ago) but I'm happy to review and merge PRs

eddyerburgh avatar Feb 04 '22 19:02 eddyerburgh