1.4.1 • Published 5 years ago
@outcome-co/jest-serializer-vue v1.4.1
jest-serializer-vue-js
A simplified version of jest-serializer-vue-tjw that allows you to stringify both attrs and props.
Installation
npm install --save-dev @outcome-co/jest-serializer-vueUsage
You need to add the serializer to your Jest config.
snapshotSerializers: ["<rootDir>/node_modules/@outcome-co/jest-serializer-vue"]Then just use .toMatchSnapshot('snapshot name') in your tests.
Example
import { shallowMount } from '@vue/test-utils'
import MyComponent from './MyComponent.vue'
describe('MyComponent.vue', () => {
describe('Created', () => {
test('Renders correctly with default props', () => {
const wrapper = shallowMount(MyComponent)
expect(wrapper).toMatchSnapshot()
})
})
})Settings
In your vue.config.js file:
module.exports = {
pluginOptions: {
jestSerializer: {
// All available formatting options: https://github.com/beautify-web/js-beautify/blob/master/js/src/html/options.js
formatting: {
indent_char: ' ',
indent_inner_html: true,
indent_size: 2,
inline: [],
sep: '\n',
unformatted: ['code', 'pre']
},
stringify: false
}
}
}| Setting | Default | Description |
|---|---|---|
| formatting | See above example | These options format the snapshot. See all available options here. |
| stringify | false | Replaces title="[object Object]" with title="{a:'asdf'}" in your snapshots, allowing you to see the data in the snapshot. Requires you to pass in wrapper, not wrapper.html(). You can specify either attributes or props, if you choose props it will serialize attributes and props. |
Development
Remember to run ./pre-commit.sh when you clone the repository.