Skip to content

Commit 32a4fb6

Browse files
inouetakuyakazupon
authored andcommitted
Fix unit testing (Airbnb style lint) (#351)
* Improve unit testing referring the official guide Unit Testing - vue.js https://vuejs.org/v2/guide/unit-testing.html * Allow optionalDependencies https://google.com/#q=import%2Fno-extraneous-dependencies 'function-bind' should be listed in the project's dependencies, not devDependencies /project-path/test/unit/index.js Function.prototype.bind = require('function-bind'); ^
1 parent 763f644 commit 32a4fb6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

template/.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ module.exports = {
4444
'js': 'never',
4545
'vue': 'never'
4646
}],
47+
// allow optionalDependencies
48+
'import/no-extraneous-dependencies': ['error', {
49+
'optionalDependencies': ['test/unit/index.js']
50+
}],
4751
{{/if_eq}}
4852
// allow debugger during development
4953
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0

template/test/unit/specs/Hello.spec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import Hello from 'src/components/Hello'{{#if_eq lintConfig "airbnb"}};{{/if_eq}
33

44
describe('Hello.vue', () => {
55
it('should render correct contents', () => {
6-
const vm = new Vue({
7-
el: document.createElement('div'),
8-
render: (h) => h(Hello){{#if_eq lintConfig "airbnb"}},{{/if_eq}}
9-
}){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
6+
const Constructor = Vue.extend(Hello){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
7+
const vm = new Constructor().$mount(){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
108
expect(vm.$el.querySelector('.hello h1').textContent)
119
.to.equal('Welcome to Your Vue.js App'){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
1210
}){{#if_eq lintConfig "airbnb"}};{{/if_eq}}

0 commit comments

Comments
 (0)