eddyerburgh / avoriaz

🔬 a Vue.js testing utility library
https://eddyerburgh.gitbooks.io/avoriaz/content/
MIT License
759 stars 62 forks source link

avoriaz cannot upgrade jsdom to ^11.0.0 #72

Closed PMK closed 7 years ago

PMK commented 7 years ago

Hi,

For my new project I used this project along with jsdom version 11 and results in an error. When using the jsdom version what avoriaz supports (^9.9.1), the error will not occur. Sadly, you cannot use avorias with Nuxt because Nuxt uses version 11.

I'm using node 8.1.2 and npm 5.0.4. Note: I'm using AVA version 0.19.1 for my tests.

My example component

<template>
  <div class="example">
    <h1>{{ message }}</h1>
    <h2>prop: {{ msg }}</h2>
    <button id="change-message" @click="changeMessage">Change message</button>
  </div>
</template>

<script>
export default {
  name: 'Example',

  data () {
    return {
      message: 'Default message'
    }
  },

  props: ['msg'],

  methods: {
    changeMessage () {
      this.message = 'new message'
    }
  }
}
</script>

Example test

import test from 'ava'
import { mount } from 'avoriaz'

// Component
import Example from '../../../components/Example.vue'

// Saving mounted instance of component
const wrapper = mount(Example)

test('renders one h1', t => {
  t.is(wrapper.find('h1').length, 1)
  // results in an error, so I add the following to check if I get HTML:
  const html = wrapper.html()
  console.log(html)
  // results in an error what is a bit clear
})

Error about the .find() function

→ npm run test-unit

> frontend@1.0.0 test-unit
> ava test/unit/specs/**/*.js

  1 failed

  renders one h1
  node_modules/window/node_modules/jsdom/lib/jsdom/living/nodes/Node-impl.js:330

  Error thrown in test

  Error:

    [TypeError: Cannot use 'in' operator to search for 'nodeType' in undefined]

  HTMLDivElementImpl.appendChild (node_modules/window/node_modules/jsdom/lib/jsdom/living/nodes/Node-impl.js:330:22)
  HTMLDivElement.appendChild (node_modules/window/node_modules/jsdom/lib/jsdom/living/generated/Node.js:132:57)
  VueWrapper.html (node_modules/avoriaz/dist/Wrapper.js:212:11)
  Test.fn (test/unit/specs/Example.test.js:11:31)

  test/unit/specs/Example.test.js exited with a non-zero exit code: 1

Error about the .html() function

node_modules/window/node_modules/jsdom/lib/jsdom/living/nodes/Node-impl.js:330
    if (!("nodeType" in newChild)) {
                     ^

TypeError: Cannot use 'in' operator to search for 'nodeType' in undefined
    at HTMLDivElementImpl.appendChild (node_modules/window/node_modules/jsdom/lib/jsdom/living/nodes/Node-impl.js:330:22)
    at HTMLDivElement.appendChild (node_modules/window/node_modules/jsdom/lib/jsdom/living/generated/Node.js:132:57)
    at VueWrapper.html (node_modules/avoriaz/dist/Wrapper.js:212:11)
    at Object.<anonymous> (test/unit/specs/Example.test.js:13:41)
    at Module._compile (module.js:569:30)
    at extensions.(anonymous function) (node_modules/require-precompiled/index.js:13:11)
    at Object.require.extensions.(anonymous function) [as .js] (node_modules/ava/lib/process-adapter.js:100:4)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (node_modules/ava/lib/test-worker.js:49:1)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

Probably jsdom is breaking avoriaz somehow... See https://github.com/tmpvar/jsdom/commit/58a7028d0d5b6aacc5b435daee9fd8f9eacbb14c

eddyerburgh commented 7 years ago

How are you loading JSDOM?

I used your component and test in an avoriaz-ava example using JSDOM 11 and it's passing - https://github.com/eddyerburgh/avoriaz-ava-example/tree/jsdom-11-example

PMK commented 7 years ago

Thanks for the demo you provided. I do not know what the problem was, but it works without errors. I updated jsdom to 11.1.0 and Avoriaz to 2.4.2, I removed the complete node_modules directory and it seems working.