Vuegister plugin for Babel.
Issues with the output should be reported on the Babel issue tracker.
npm i vuegister-plugin-babel -D
To run test suite create test.js
and MyComponent.vue
files inside your test
folder.
Content of the test.js
file:
const assert = require('chai').assert;
const Vue = require('vue/dist/vue.common')
const MyComponent = require('./MyComponent.vue').default
describe('MyComponent', () => {
it('has a created hook', () => {
assert.isFunction(MyComponent.created)
})
it('sets the correct default data', () => {
assert.isFunction(MyComponent.data)
const defaultData = MyComponent.data()
assert.strictEqual(defaultData.message, 'hello!')
})
it('correctly sets the message when created', () => {
const vm = new Vue(MyComponent).$mount()
assert.strictEqual(vm.message, 'bye!')
})
})
Content of the MyComponent.vue
file:
<template>
<span>{{ message }}</span>
</template>
<script lang="babel">
export default {
data () {
return {
message: 'hello!'
}
},
created () {
this.message = 'bye!'
}
}
</script>
Install jsdom-global and run tests with:
npm i jsdom jsdom-global -D
mocha -r jsdom-global/register -r vuegister/register
Babel transpiles this code:
export default {
data () {
return {
message: 'hello!'
}
}
}
into this:
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
data() {
return {
message: 'hello!'
};
}
};
So now you have to call .default
in Node.js code:
var foo = require('foo').default
To run the test suite, install development dependencies and execute:
npm run coverage
Distributed under MIT License.