Skip to content

Instantly share code, notes, and snippets.

@otavio-paganotti
Last active January 10, 2019 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otavio-paganotti/a11de6be0bb22c6c8b7429adbd5d0f31 to your computer and use it in GitHub Desktop.
Save otavio-paganotti/a11de6be0bb22c6c8b7429adbd5d0f31 to your computer and use it in GitHub Desktop.
Error with @vue/cli-plugin-unit-mocha, doesn't recognize M from Materialize-css
$ npm run test:unit
> APP@2019.1.1 test:unit Disco:\caminho\da\aplicação
> vue-cli-service test:unit -c -w
WEBPACK Compiling...
DONE Compiled successfully in 7910ms
WEBPACK Compiled successfully in 7910ms
MOCHA Testing...
RUNTIME EXCEPTION Exception occurred while loading your tests
ReferenceError: M is not defined
at Disco:\caminho\da\aplicação\dist\webpack:\node_modules\materialize-css\dist\js\materialize.js:1070:1
at Object.<anonymous> (Disco:\caminho\da\aplicação\dist\webpack:\node_modules\materialize-css\dist\js\materialize.js:1071:1)
at Object../node_modules/materialize-css/dist/js/materialize.js (Disco:\caminho\da\aplicação\dist\main.js:150230:30)
at __webpack_require__ (Disco:\caminho\da\aplicação\dist\webpack:\webpack\bootstrap:19:1)
at Module../src/store/store.js (Disco:\caminho\da\aplicação\dist\webpack:\src\store\store.js:1:1)
at __webpack_require__ (Disco:\caminho\da\aplicação\dist\webpack:\webpack\bootstrap:19:1)
at Module../src/router/index.js (Disco:\caminho\da\aplicação\dist\webpack:\src\router\index.js:1:1)
at __webpack_require__ (Disco:\caminho\da\aplicação\dist\webpack:\webpack\bootstrap:19:1)
at Module.<anonymous> (Disco:\caminho\da\aplicação\dist\main.js:42484:106)
at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/login.vue?vue&type=script&lang=js& (Disco:\caminho\da\aplicação\dist\main.js:42586:30)
at __webpack_require__ (Disco:\caminho\da\aplicação\dist\webpack:\webpack\bootstrap:19:1)
at Module../src/components/login.vue?vue&type=script&lang=js& (Disco:\caminho\da\aplicação\dist\webpack:\src\components\login.vue?7c3c:1:1)
at __webpack_require__ (Disco:\caminho\da\aplicação\dist\webpack:\webpack\bootstrap:19:1)
at Module../src/components/login.vue (Disco:\caminho\da\aplicação\dist\webpack:\src\components\login.vue:1:1)
at __webpack_require__ (Disco:\caminho\da\aplicação\dist\webpack:\webpack\bootstrap:19:1)
at Module../tests/unit/Login/login.spec.js (Disco:\caminho\da\aplicação\dist\webpack:\tests\unit\Login\login.spec.js:1:1)
at __webpack_require__ (Disco:\caminho\da\aplicação\dist\webpack:\webpack\bootstrap:19:1)
at run (Disco:\caminho\da\aplicação\dist\webpack:\node_modules\mocha-webpack\lib\entry.js:3:1)
at Array.forEach (<anonymous>)
at Object../node_modules/mocha-webpack/lib/entry.js (Disco:\caminho\da\aplicação\dist\webpack:\node_modules\mocha-webpack\lib\entry.js:10:1)
at __webpack_require__ (Disco:\caminho\da\aplicação\dist\webpack:\webpack\bootstrap:19:1)
at Disco:\caminho\da\aplicação\dist\webpack:\webpack\bootstrap:83:1
at Object.<anonymous> (Disco:\caminho\da\aplicação\dist\main.js:87:10)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object._module2.default._extensions.(anonymous function) [as .js] (Disco:\caminho\da\aplicação\node_modules\mocha-webpack\lib\util\registerRequireHook.js:148:12)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Disco:\caminho\da\aplicação\node_modules\mocha\lib\mocha.js:250:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (Disco:\caminho\da\aplicação\node_modules\mocha\lib\mocha.js:247:14)
at Mocha.run (Disco:\caminho\da\aplicação\node_modules\mocha\lib\mocha.js:576:10)
at runMocha (Disco:\caminho\da\aplicação\node_modules\mocha-webpack\lib\runner\TestRunner.js:244:35)
at Disco:\caminho\da\aplicação\node_modules\mocha-webpack\lib\runner\TestRunner.js:300:13
at Disco:\caminho\da\aplicação\node_modules\mocha-webpack\lib\webpack\compiler\registerReadyCallback.js:26:7
at AsyncSeriesHook.eval [as callAsync] (eval at create (Disco:\caminho\da\aplicação\node_modules\tapable\lib\HookCodeFactory.js:32:10), <anonymous>:36:1)
at AsyncSeriesHook.lazyCompileHook (Disco:\caminho\da\aplicação\node_modules\tapable\lib\Hook.js:154:20)
at Watching._done (Disco:\caminho\da\aplicação\node_modules\webpack\lib\Watching.js:97:28)
at compiler.emitRecords.err (Disco:\caminho\da\aplicação\node_modules\webpack\lib\Watching.js:72:19)
at Compiler.emitRecords (Disco:\caminho\da\aplicação\node_modules\webpack\lib\Compiler.js:371:39)
at compiler.emitAssets.err (Disco:\caminho\da\aplicação\node_modules\webpack\lib\Watching.js:53:20)
at hooks.afterEmit.callAsync.err (Disco:\caminho\da\aplicação\node_modules\webpack\lib\Compiler.js:357:14)
at _err0 (eval at create (Disco:\caminho\da\aplicação\node_modules\tapable\lib\HookCodeFactory.js:32:10), <anonymous>:11:1)
at callback (Disco:\caminho\da\aplicação\node_modules\copy-webpack-plugin\dist\index.js:126:17)
at afterEmit (Disco:\caminho\da\aplicação\node_modules\copy-webpack-plugin\dist\index.js:220:13)
at AsyncSeriesHook.eval [as callAsync] (eval at create (Disco:\caminho\da\aplicação\node_modules\tapable\lib\HookCodeFactory.js:32:10), <anonymous>:7:1)
at AsyncSeriesHook.lazyCompileHook (Disco:\caminho\da\aplicação\node_modules\tapable\lib\Hook.js:154:20)
at asyncLib.forEach.err (Disco:\caminho\da\aplicação\node_modules\webpack\lib\Compiler.js:354:27)
at Disco:\caminho\da\aplicação\node_modules\neo-async\async.js:2825:7
at done (Disco:\caminho\da\aplicação\node_modules\neo-async\async.js:2861:11)
at Disco:\caminho\da\aplicação\node_modules\neo-async\async.js:2813:7
at MemoryFileSystem.writeFile (Disco:\caminho\da\aplicação\node_modules\memory-fs\lib\MemoryFileSystem.js:328:9)
at writeOut (Disco:\caminho\da\aplicação\node_modules\webpack\lib\Compiler.js:338:29)
at Immediate._onImmediate (Disco:\caminho\da\aplicação\node_modules\memory-fs\lib\MemoryFileSystem.js:288:4)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
import { expect } from 'chai'
import { shallowMount } from '@vue/test-utils'
import login from '@/components/login'
describe('Login.vue', () => {
it('renders props.msg when passed', () => {
const msg = 'new message'
const wrapper = shallowMount(login, {
propsData: { msg }
})
expect(wrapper.text()).to.include(msg)
})
})
<template>
<div id="login">
<h1>{{msg}}</h1>
</div>
</template>
<script>
export default {
name: 'login-component',
props: ['msg']
}
</script>
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import VueHead from 'vue-head'
import './Filters/filters'
import './Mixins/mixins'
import './registerServiceWorker'
import App from './App'
import router from './router'
import store from './store/store'
import 'materialize-css'
import 'materialize-css/dist/css/materialize.css'
import '../public/css/font-awesome/css/font-awesome.min.css'
import '../public/css/c3/c3.min.css'
import 'animate.css/animate.min.css'
import 'vue-multiselect/dist/vue-multiselect.min.css'
import VueTheMask from 'vue-the-mask'
import Money from 'v-money'
Vue.use(VueTheMask)
Vue.use(Money)
Vue.router = router
Vue.use(VueHead)
Vue.use(Vuex)
axios.defaults.baseURL = process.env.VUE_APP_API_KEY
Vue.config.productionTip = process.env.NODE_ENV === 'development'
Vue.config.devtools = process.env.NODE_ENV === 'development'
Vue.config.silent = process.env.NODE_ENV === 'development'
export const bus = new Vue()
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
{
"name": "APP",
"version": "2019.1.1",
"private": true,
"description": "Desenvolvimento da aplicação",
"author": "Otávio Paganotti <otavio@otavio.com.br>",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test:e2e": "vue-cli-service test:e2e",
"test:unit": "vue-cli-service test:unit -c -w"
},
"dependencies": {
"@handsontable/vue": "^3.0.0",
"@material/select": "^0.41.0",
"@websanova/vue-auth": "^2.21.3-beta",
"animate.css": "^3.7.0",
"axios": "^0.18.0",
"bootstrap-vue": "^2.0.0-rc.1",
"c3": "^0.6.8",
"datatables.net-dt": "^1.10.16",
"file-saverjs": "^1.3.6",
"handsontable": "^5.0.1",
"lodash": "^4.17.11",
"materialize-css": "^1.0.0-rc.2",
"materialize-tags": "^1.2.3",
"moment": "^2.21.0",
"register-service-worker": "^1.5.2",
"sweetalert": "^2.1.0",
"tableexport": "^5.0.3",
"v-money": "^0.8.1",
"vue": "^2.5.17",
"vue-axios": "^2.1.4",
"vue-c3": "^1.2.9",
"vue-head": "^2.0.12",
"vue-input-tag": "^1.0.3",
"vue-moment": "^3.2.0",
"vue-multiselect": "^2.1.3",
"vue-rangedate-picker": "^0.3.4",
"vue-router": "^3.0.1",
"vue-select": "^2.5.1",
"vue-table-component": "^2.0.0-alpha.1",
"vue-text-mask": "^6.1.2",
"vue-the-mask": "^0.11.1",
"vue-trumbowyg": "^3.4.0",
"vue2-datepicker": "^2.6.3",
"vuejs-auto-complete": "^0.6.5",
"vuejs-datepicker": "^0.9.29",
"vuex": "^3.0.1"
},
"devDependencies": {
"@johmun/vue-tags-input": "^1.5.9",
"@voerro/vue-tagsinput": "^1.10.0",
"@vue/cli-plugin-babel": "^3.2.0",
"@vue/cli-plugin-e2e-nightwatch": "^3.2.0",
"@vue/cli-plugin-eslint": "^3.2.0",
"@vue/cli-plugin-pwa": "^3.2.0",
"@vue/cli-plugin-unit-mocha": "^3.2.0",
"@vue/cli-service": "^3.2.0",
"@vue/test-utils": "^1.0.0-beta.20",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"chai": "^4.1.2",
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jquery": "^3.3.1",
"moxios": "^0.4.0",
"node-sass": "^4.9.0",
"nyc": "^13.1.0",
"sass-loader": "^7.0.1",
"vue-head": "^2.0.12",
"vue-template-compiler": "^2.5.21"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
},
"globals": {
"$": true,
"jQuery": true,
"M": true
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
var webpack = require('webpack')
process.env.VUE_APP_VERSION_APP = require('./package.json').version
module.exports = {
configureWebpack: {
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
jQuery: 'jquery'
})
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment