vue-test-utils extension
Simple little trick to make vue-test-utils extendible.
Installation
npm install --save-dev vtu-extension
Example usage
Create a file vue-test-util-ext.js
in you root directory:
// ./vue-test-util-ext.js var vtu = ; moduleexports = vtuexportDefault;
Now you can extend the vue-test-utils classes like so:
// ./vue-test-util-ext.js var vtu = ; /** * It checks if an element is hidden */ vtu; moduleexports = vtuexportDefault;
Careful!! Notice that we are exporting
vtu.exportDefault
. This is necessary to maintain the default functionality of vue-test-utils.
On your test file, you should import ./vue-test-util-ext.js
instead of vue-test-util
and now you have access to the method:
// ./specs/example.spec.js var vtu = ; var example = template: `<div class="hiddenDiv" v-show="false">This should be hidden</div>` var wrapper = vtu; wrapper // return => true
Methods
define(module, methodName, callback)
Sets a new prototype function on a given vue-test-utils
module.
module
: Are classes and objects contained in the originalvue-test-utils
file. e.g.: Wrapper, WrapperArray, ...methodName
: The new method namecallback
: The callback function
Example
vtu;
get(name)
It gets variables and functions declared withing the vue-test-utils
file.
name
: Is the name of the variable/function contained in the originalvue-test-utils
file.
Example
var throwError = vtu; ifsomethingWentWrong ; // "[vue-test-utils]: Something went wrong"