I am writing unit tests in a Vue 2.0 app using PhantomJS, Karma, Mocha and Chai and while the tests pass, I get a warning with each test that looks like this:
ERROR: '[Vue warn]: Failed to resolve directive: highlightjs (found in <UnitTest>)
I would either like to find a way to ignore warnings about custom directives or somehow make the tests aware of them.
=== Possibly related, possibly separate error ===
When I force one of my tests to fail I am getting an error that looks like:
npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "unit"
npm ERR! node v7.6.0
npm ERR! npm v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! vuestack@1.0.0 unit: `cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vuestack@1.0.0 unit script 'cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vuestack package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs vuestack
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls vuestack
npm ERR! There is likely additional logging output above.
Other tests still pass but this error shows up when they've all run. Have tried uninstalling / reinstalling node modules, as well as switching Node versions around.
Doh! Solved:
import VueHighlightJS from 'vue-highlightjs'
Vue.use(VueHighlightJS);
I found the answer to the question here. Incidentally, a blog post by the creator of the component I was struggling with. Looks like you need to include custom components using Vue.use() in each separate testing file.