Comments (5)
I'm pretty busy atm but would happily accept a PR adding support
from jest-serializer-vue.
Would Vue 3 support ever get added?
from jest-serializer-vue.
Bumping this up
from jest-serializer-vue.
For anyone needing a way to at least come close to the snapshot output with Vue 3 components, this might be useful:
Install diffable-html:
yarn add -D diffable-html
Create a file snapshot-serializer.js
const toDiffableHtml = require('diffable-html')
module.exports = {
test(received) {
return received instanceof HTMLElement
},
print(received) {
return toDiffableHtml(received.outerHTML).trim()
},
}
Add it to jest.config.js
:
module.exports = {
...
snapshotSerializers: ['<rootDir>/tests/unit/snapshot-serializer'],
...
}
Unfortunately this does not support test-utils wrapper, so you need to pass in their element like so:
expect(wrapper.element).toMatchSnapshot()
Be aware that this will still alter the snapshot outcome compared to what jest-serializer-vue
did with Vue 2 components. But it came close enough for our use case.
from jest-serializer-vue.
From a quick look, it doesn't work because isVueInstance
property was already deprecated in @vue/test-utils@1
and as such it does not exist in v2 (for vue3). That property is used to assert if the input is a @vue/test-utils
wrapper. In theory, a quick fix would be to replace this check with another one, for example:
const isVueWrapper = received => (
received &&
typeof received === 'object' &&
- typeof received.isVueInstance === 'function'
+ typeof received.html === 'function'
Lines 4 to 7 in 600b2c0
Alternatives
Just call .html()
beforehand in your tests.
it('smokes', () => {
const wrapper = shallowMount(Component);
- expect(wrapper).toMatchSnapshot();
+ expect(wrapper.html()).toMatchSnapshot();
});
from jest-serializer-vue.
Related Issues (13)
- Conditional child component set to false should not be included in output
- Meaningful router to value in snapshot HOT 1
- Change (or expose) "pretty" options HOT 1
- Bug in the Readme HOT 2
- render objects HOT 3
- Support `v-slot` token HOT 2
- Feature parity with jest-serializer-vue-tjw
- Istanbul coverage interference HOT 3
- Would you consider an API for custom html.replace functionality? HOT 2
- Change output directory HOT 1
- Release notes for 2.0.0 are too sparse HOT 4
- TypeError: Cannot read property 'replace' of undefined HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest-serializer-vue.