vue-function-tester
vue-function-tester makes method unit testing for Vue components easier and shorter by providing mock functions and helper objects.
Features
Providing mock functions and helper objects for unit testing and they help to reduce steps and codes.
Supporting...
- methods
- lifecycle hooks
- computed
- watch
vue-function-helper dependents on Jest.
Installation
$ npm install -D vue-function-tester
or
$ yarn add -D vue-function-tester
Usage
methods
See spec if you want more detailed examples.
// SampleComponent.vue { return liked: false ; } methods: { return 'Hi!'; } { return `Hi, `!; } { thisliked = true; } { return this; } { // called by other methods } { this } async { let returnVal = ''; const sleep = { ; }; await ; return returnVal; } // yourMethodsTest.spec.js;; ;
lifecycle hooks
See spec if you want more detailed examples.
// SampleComponent.vue { return updatedCount: 0 loading: false ; } async { thisloading = true; await this; thisloading = false; } { this; } { thisupdatedCount++; } { ; } methods: async { // ... } ); // yourHooksTest.spec.js;; ;
computed
See spec if you want more detailed examples.
// SampleComponent.vue computed: { return 'Hello!'; } displayName: { return `Mr. `; } { this; } ); // yourComputedTest.spec.js;; ;
watch
See spec if you want more detailed examples.
// SampleComponent.vue props: count: type: Number required: true { return output: '' } watch: { if newVal % 15 === 0 thisoutput = 'Fizz Buzz' else this; } methods: { ... } ); // yourWatchTest.spec.js;; ;
alias
vue-function-test provides some alias.
// normal usage; // shorten run; // function properties;;
License
MIT