Nuxt.js: Unit Tests Setup

Created on 22 Sep 2017  路  12Comments  路  Source: nuxt/nuxt.js

I see that Nuxt.js comes already with e2e tests setup.
However, for my project I would like also to implement Karma Mocha and Chai to write unit tests for my components and for the Vuex store.

Someone has any suggestion on how to go about it ?
Is there any plan to integrate unit tests in the nuxt.config.js in the future ?

Thanks for the wonderful work by the way, Nuxt is fantastic!

This question is available on Nuxt.js community (#c1529)
contributions welcome

Most helpful comment

All 12 comments

I would love to see some examples as well

Not exactly karma-mocha-chai, but here's how I configured jest and puppeteer for nuxt, maybe it'll help: https://github.com/studbits/nuxt-jest-puppeteer

Hi @alidcastano, awesome! Thanks for pointing this out, I'll try this

The official VueJS test framework vue-test-utils is using mocha-webpack, where you can specify a webpack-config file. I'm now trying to get Mocha working in Nuxt using vue-test-utils... Does Nuxt expose its generated Webpack config?

mocha-webpack --webpack-config mocha-webpack.config.js --require test/_helpers/mocha-setup.js test/unit/**/*.spec.js

Should I use dllWebpackConfig from the Nuxt core? Or do I need to use a hook on the Builder class? I'm kinda lost...
(I expect to get an object with all Webpack configurations)

Edit: also vue-styleguidist requires a Webpack config.

Edit (03/03): I got it working by creating a mocha-webpack.conf.js file with the stuff I need from Nuxt, but I prefer to see something from Nuxt itself.

@PMK is it possible for you to share the content of mocha-webpack.config.js and mocha-setup.js? I am a bit lost with stuff like babel and some recent Javascript syntax that I am not able to make mocha work with vue.js and nuxt.js.

@pi0 @Atinux any answer to @PMK question in regards to getting an export of nuxt's webpack.config? Maybe expose it as part of the /dist folder as it builds?

Not right now, but I plan to be able to get programmatically the webpack config so it could be plugged into any testing tool that need the Webpack config.

looking forward to it!

+1 for this

Resolved by #4163 and #4116. For e2e: https://github.com/melrefaie/nuxt-cypress

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

o-alexandrov picture o-alexandrov  路  3Comments

vadimsg picture vadimsg  路  3Comments

surmon-china picture surmon-china  路  3Comments

bimohxh picture bimohxh  路  3Comments

gary149 picture gary149  路  3Comments