Giter VIP home page Giter VIP logo

vue-test-utils-jest-example's Issues

Testing a plugin

After much Googling I'm coming up short on how to test a Vue plugin using Jest without getting the rather annoying warning log:

You are running Vue in development mode.

I've searched an searched on how to disable/mute/appease this and the only solution I have found that works is to set NODE_ENV to "production" before running jest:

"test": "cross-env NODE_ENV=production jest"

Since jest sets NODE_ENV to "test" by default, I'm not sure if this has any side effects or not?
Either way, it feels a little wrong to me.


As a really simple test case, let's say I have a plugin that looks like this:

// plugin.js
export default {
  install(Vue, options) {
    Vue.prototype.$upper = (text) => text.toUpperCase()
  }
}

...then if I wanted to test this plugin, my test file might look something like this:

// plugin.spec.js
import Vue from 'vue'
import VueUpper from './plugin'

it('adds an $upper method to the Vue prototype', () => {
  expect(Vue.prototype.$upper).toBeUndefined()
  Vue.use(VueUpper)
  expect(typeof Vue.prototype.$upper).toBe('function')
})

it('transforms a string to upper case', () => {
  expect(Vue.prototype.$upper('foo')).toBe('FOO')
})

Any help would be very much appreciated!

Cannot find module './src/components/Message' from 'MessageToggle.vue'

If I use an alias to resolve my components path e.g. import Message from '@/components/Message' instead of import Message from ./Message, my tests fail.

Cannot find module './src/components/Message' from 'MessageToggle.vue'

I can temporarly use relative paths instead of @/, but using aliases is extremely convenient for me and my team ...

Lines in coverage report are incorrect

// List.spec.js
describe('List.vue', () => {
  it('renders li for each item in props.items', () => {
    // const items = ['', '']
    // const wrapper = shallow(List, {
    //   propsData: { items }
    // })
    // expect(wrapper.findAll('li')).toHaveLength(items.length)
  })
})

[bug] can not yarn unit

steps to reproduce

expected behavior

test pass

actual behavior

yarn unit
yarn unit v0.23.4
$ jest 
 PASS  test/specs/Message.spec.js
 FAIL  test/specs/List.spec.js
  ● Test suite failed to run

    Couldn't find preset "es2015" relative to directory "/Volumes/DevelopOnly/Github/vue-test-utils-jest-example"
      
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
          at Array.map (<anonymous>)

 FAIL  test/specs/MessageToggle.spec.js
  ● Test suite failed to run

    Couldn't find preset "es2015" relative to directory "/Volumes/DevelopOnly/Github/vue-test-utils-jest-example"
      
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
          at Array.map (<anonymous>)

Test Suites: 2 failed, 1 passed, 3 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        4.532s
Ran all test suites.
error Command failed with exit code 1.

description

same with npm install && npm run unit

  • OS version: macOS 10.12.6
  • yarn version: v0.23.4
  • node version: v8.4.0
  • npm version: 5.3.0

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.