Testing Vue Global Variables

Posted 11 months ago by nate.a.johnson

Hello,

I am going through the Testing Vue series right now and things work great in there with small examples. Now I am trying to apply it to my current application, which has quite a few more moving pieces. I am running into an issue where Mocha can't find a global variable. The reason is that there is a script section at the bottom of my app.blade.php layout file that puts some variables into global memory for the Vue components to use once they get mounted. This code executes on the server using PHP, as any normal Laravel app does. Has anyone else figured out a good way to make this work?

 WEBPACK  Compiled successfully in 2082ms

 MOCHA  Testing...

 RUNTIME EXCEPTION  Exception occurred while loading your tests

ReferenceError: userEventTypeOptions is not defined
    at Object.<anonymous> (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:47709:46)
    at __webpack_require__ (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:20:30)
    at Object.defineProperty.value (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:36935:16)
    at __webpack_require__ (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:20:30)
    at Object.<anonymous> (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:36798:22)
    at __webpack_require__ (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:20:30)
    at Object.disposed (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:36750:16)
    at __webpack_require__ (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:20:30)
    at run (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:18459:20)
    at Array.forEach (native)
    at Object.<anonymous> (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:18466:24)
    at Object.<anonymous> (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:18467:30)
    at __webpack_require__ (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:20:30)
    at /Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:63:18
    at Object.<anonymous> (/Users/nate/Code/bluesky/.tmp/mocha-webpack/1511894009397/bundle.js:66:10)
    at Module._compile (module.js:570:32)
    at Object._module2.default._extensions.(anonymous function) [as .js] (/Users/nate/Code/bluesky/node_modules/mocha-webpack/lib/util/registerRequireHook.js:147:12)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at /Users/nate/Code/bluesky/node_modules/mocha/lib/mocha.js:231:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/nate/Code/bluesky/node_modules/mocha/lib/mocha.js:228:14)
    at Mocha.run (/Users/nate/Code/bluesky/node_modules/mocha/lib/mocha.js:514:10)
    at /Users/nate/Code/bluesky/node_modules/mocha-webpack/lib/runner/TestRunner.js:198:25
    at Compiler.<anonymous> (/Users/nate/Code/bluesky/node_modules/mocha-webpack/lib/webpack/compiler/registerReadyCallback.js:26:7)
    at Compiler.applyPlugins (/Users/nate/Code/bluesky/node_modules/tapable/lib/Tapable.js:61:14)
    at emitRecords.err (/Users/nate/Code/bluesky/node_modules/webpack/lib/Compiler.js:268:11)
    at Compiler.emitRecords (/Users/nate/Code/bluesky/node_modules/webpack/lib/Compiler.js:375:38)
    at emitAssets.err (/Users/nate/Code/bluesky/node_modules/webpack/lib/Compiler.js:262:10)
    at applyPluginsAsyncSeries1.err (/Users/nate/Code/bluesky/node_modules/webpack/lib/Compiler.js:368:12)
    at next (/Users/nate/Code/bluesky/node_modules/tapable/lib/Tapable.js:218:11)
    at Compiler.compiler.plugin (/Users/nate/Code/bluesky/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
    at Compiler.applyPluginsAsyncSeries1 (/Users/nate/Code/bluesky/node_modules/tapable/lib/Tapable.js:222:13)
    at Compiler.afterEmit (/Users/nate/Code/bluesky/node_modules/webpack/lib/Compiler.js:365:9)
    at require.forEach.err (/Users/nate/Code/bluesky/node_modules/webpack/lib/Compiler.js:354:15)
    at /Users/nate/Code/bluesky/node_modules/async/dist/async.js:421:16
    at iteratorCallback (/Users/nate/Code/bluesky/node_modules/async/dist/async.js:998:13)
    at /Users/nate/Code/bluesky/node_modules/async/dist/async.js:906:16
    at MemoryFileSystem.writeFile (/Users/nate/Code/bluesky/node_modules/memory-fs/lib/MemoryFileSystem.js:328:9)
    at writeOut (/Users/nate/Code/bluesky/node_modules/webpack/lib/Compiler.js:343:28)
    at require.forEach (/Users/nate/Code/bluesky/node_modules/webpack/lib/Compiler.js:349:12)
    at /Users/nate/Code/bluesky/node_modules/async/dist/async.js:3083:16
    at eachOfArrayLike (/Users/nate/Code/bluesky/node_modules/async/dist/async.js:1003:9)
    at eachOf (/Users/nate/Code/bluesky/node_modules/async/dist/async.js:1051:5)
    at Object.eachLimit (/Users/nate/Code/bluesky/node_modules/async/dist/async.js:3145:5)
    at emitFiles (/Users/nate/Code/bluesky/node_modules/webpack/lib/Compiler.js:319:21)
    at Immediate.<anonymous> (/Users/nate/Code/bluesky/node_modules/memory-fs/lib/MemoryFileSystem.js:288:4)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

Thanks!

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.