Coder Social home page Coder Social logo

vue-template-loader-jest's Introduction

Vue Template Loader Jest

With vue-template-loader it is possible to extract the html from a typescript single file component to a separate .html file (see https://github.com/ktsn/vue-template-loader). But loading the components in jest tests is not possible anymore.

Here this library comes into play. It is basically just a custom transformer for jest that is using vue-template-loader to compile the template.

Reception

This is untested at all and I only care about my issues. Contributors are highly welcome. Feel free to open pull requests and issues. Write when you are interested in maintaining it.

Usage

Just install this library and add it to your jest config .*html: 'vue-template-loader-jest'. Example:

{
   "jest": {
       "moduleFileExtensions": [
         "js",
         "ts",
         "html"
       ],
       "transform": {
         "^.+\\.tsx?$": "ts-jest",
         "^.+\\.html$": "vue-template-loader-jest"
       },
       "moduleNameMapper": {
         "@view/(.*)": "<rootDir>/resources/views/components/$1"
       }
   }
}

As you can see I'm also using a custom alias for views.

vue-template-loader-jest's People

Contributors

tflori avatar

Stargazers

Andrei Kovalev avatar  avatar

Watchers

James Cloos avatar  avatar

vue-template-loader-jest's Issues

wrapper.find() hasn't access to template

For testing purpose, I try to trigger an event on some html element inside my component for check if my vuex action triggered. In my .spec file I try this:

import Component from '../../../src/components/component'

localVue.use(Vuex)

describe('Component', () => {

  beforeEach(() => {
    actions = {
      actionClick: jest.fn()
    }
    store = new Vuex.Store({
      state: {},
      actions
     })
  })

  it('trigget "actionClick" by button click', () => {
    const wrapper = shallowMount(Component, { store, localVue })
    wrapper.find('button').trigger('click')
    expect(actions.actionClick).toHaveBeenCalled()
  })
})

Template is simple:
<button @click="triggerClick">test</button>

But I have nothing except
[vue-test-utils]: find did not return button, cannot call trigger() on empty Wrapper
Did I miss something?

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.