diff --git a/template/README.md b/template/README.md index 11be17b..45c6ecf 100644 --- a/template/README.md +++ b/template/README.md @@ -31,7 +31,7 @@ available in the window['{{name}}'] variable. ## Tests -This template uses karma by default, you can change test settings in poi.config.js +This template uses karma with chai by default, you can change test settings in poi.config.js `npm run test` `npm run test:watch` diff --git a/template/package.json b/template/package.json index d41f3ee..20b9f2c 100644 --- a/template/package.json +++ b/template/package.json @@ -27,8 +27,12 @@ }, "devDependencies": { "babel-preset-es2015": "^6.24.1", + "chai": "^4.1.2", "eslint": "^3.17.1", "eslint-plugin-vue": "beta", + "karma-chai": "^0.1.0", + "karma-phantomjs-launcher": "^1.0.4", + "karma-phantomjs-shim": "^1.5.0", "node-glob": "^1.2.0", "poi": "^9.3.10", "poi-preset-karma": "^9.1.0", diff --git a/template/poi.config.js b/template/poi.config.js index 6629a8c..4b79433 100644 --- a/template/poi.config.js +++ b/template/poi.config.js @@ -1,4 +1,5 @@ const presetKarma = require('poi-preset-karma'); +const webpack = require('webpack'); const glob = require('glob').sync; const {name} = require('./package.json'); @@ -7,13 +8,13 @@ module.exports = { filename: { js: name + '.min.js', }, - sourceMap: false, + sourceMap: true, html: false, presets: [ presetKarma({ - files: ['test/specs/**/*.spec.js'], + files: ['./test/specs/**.spec.js'], browsers: ['PhantomJS'], - frameworks: ['mocha', 'sinon-chai', 'phantomjs-shim'], + frameworks: ['mocha', 'chai', 'phantomjs-shim'], }) - ] + ], }; diff --git a/template/test/index.js b/template/test/index.js deleted file mode 100644 index 2993384..0000000 --- a/template/test/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import Vue from 'vue'; - -Vue.config.productionTip = false; - -// require all test files (files that ends with .spec.js) -const testsContext = require.context('./specs', true, /\.spec$/); -testsContext.keys().forEach(testsContext); - -// require all src files that ends with .js or .vue for coverage. -// you can also change this to match only the subset of files that -// you want coverage for. -const srcContext = require.context('../src', true, /^\.\/.+\.(vue|js)$/); -srcContext.keys().forEach(srcContext); diff --git a/template/test/specs/Component.spec.js b/template/test/specs/Component.spec.js index 805eec7..f427fda 100644 --- a/template/test/specs/Component.spec.js +++ b/template/test/specs/Component.spec.js @@ -2,11 +2,16 @@ import Vue from 'vue'; import Component from '../../src/{{ name }}/{{ name }}'; describe('{{ name }}.vue', () => { - it('should render correct contents', () => { - const Constructor = Vue.extend(Component); - const propsData = {text: 'Test text'}; + const Constructor = Vue.extend(Component); + const propsData = {text: 'Test text'}; + + it('should instance the right component', () => { + const vm = new Constructor({propsData}); + expect(vm.$options.name).to.equal('{{ name }}'); + }); + + it('should render correct content', () => { const vm = new Constructor({propsData}).$mount(); - expect(vm.$el.querySelector('strong').textContent) - .to.equal(propsData.text); + expect(vm.$el.innerHTML).to.equal(propsData.text); }); });