Skip to content

including unit tests in vue component #223

Closed
@paulpflug

Description

@paulpflug

For unit testing of standalone components, I have a vue environment file where I load the component and interact with it. I often find myself switching between the environment file and the file containing the unit test fore and back..

This would very much simplify the unit testing.
this:

<template><someComp></someComp></template>
<script>
module.exports = {
  components: {
    someComp: // the component to test
  }
  // other stuff to interact with someComp
}
</script>
<script test="karma">
describe("comp", function() {
  it("should work", function() {
    //the test
  })
})
</script>

compiles to this:

module.exports = {
  components: {
    someComp: // the component to test
  }
  // other stuff to interact with someComp
};

if (module.exports.__esModule) module.exports = module.exports.default
;(typeof module.exports === "function"? module.exports.options: module.exports).template = "<someComp></someComp>"

// stripped in production build
if (window.__karma__ !== "null") {
  karmaTestComp = Vue.extend(module.exports)
  karmaTestComp = new karmaTestComp()
  document.body.appendChild(karmaTestComp.$mount().$el)
  describe("comp", function() {
    it("should work", function() {
      //the test
    })
  })
  document.body.removeChild(karmaTestComp.$el)
  karmaTestComp.$destroy()
}

Karma would only need to provide Vue and webpack-load the environment vue file

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions