GithubHelp home page GithubHelp logo

Comments (5)

eddyerburgh avatar eddyerburgh commented on July 28, 2024 1

I'm pretty busy atm but would happily accept a PR adding support

from jest-serializer-vue.

doutatsu avatar doutatsu commented on July 28, 2024

Would Vue 3 support ever get added?

from jest-serializer-vue.

doutatsu avatar doutatsu commented on July 28, 2024

Bumping this up

from jest-serializer-vue.

visualjerk avatar visualjerk commented on July 28, 2024

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.

renatodeleao avatar renatodeleao commented on July 28, 2024

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' 

const isVueWrapper = received => (
received &&
typeof received === 'object' &&
typeof received.isVueInstance === 'function'

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.