0

モカ + チャイを使用して、HereMaps のマップを含む VueJS コンポーネントを単体テストしようとしています。VueJS ドキュメントの公式チュートリアルに従ったところ、スムーズに進みました。

しかし、コンポーネント (HereMap を含む) を単体テストしたい場合Map.vue、コンポーネントが正しくマウントされていないようで、ターミナル エラーを回避する方法がありません。HereMap が必要とするスクリプトに問題があるのではないかと思いますが、よくわかりません。

私の単体テスト mapTest.spec.tsは次のとおりです。

import { shallowMount } from '@vue/test-utils'
import Map from '@/components/Map.vue'
import { expect } from 'chai'

describe('Map', () => {
    const wrapper = shallowMount(Map);
    it('mounts', () => {
        wrapper.setProps({latitude: 0, longitude: 0});
        expect(true).equal(true);
  })
})

行にコメントするconst wrapper = shallowMount(Map)と、エラーが消え、テストがスムーズに実行されます。

HereMap を適切に単体テストする方法を知っている人はいますか?

助けてくれてありがとう。


Mocha から得られるエラーは次のとおりです。

 RUNTIME EXCEPTION  Exception occurred while loading your tests

TypeError: self.eval is not a function
    at Window.<anonymous> (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/src/vendor/here-maps/3.1/mapsjs-core.js:34:1)
    at Object../src/vendor/here-maps/3.1/mapsjs-core.js (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/src/vendor/here-maps/3.1/mapsjs-core.js:404:1)
    at __webpack_require__ (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/webpack/bootstrap:19:1)
    at Object../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/ts-loader/index.js?!./node_modules/vuetify-loader/lib/loader.js?!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/Map.vue?vue&type=script&lang=ts& (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/src/components/Map.vue:10:1)
    at __webpack_require__ (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/webpack/bootstrap:19:1)
    at Module../src/components/Map.vue?vue&type=script&lang=ts& (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/src/components/Map.vue?0e8b:1:1)
    at __webpack_require__ (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/webpack/bootstrap:19:1)
    at Module../src/components/Map.vue (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/src/components/Map.vue?737c:1:1)
    at __webpack_require__ (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/webpack/bootstrap:19:1)
    at Object../tests/unit/map/mapTest.spec.ts (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/tests/unit/map/mapTest.spec.ts:2:1)
    at __webpack_require__ (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/webpack/bootstrap:19:1)
    at run (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/node_modules/@vue/cli-plugin-unit-mocha/node_modules/mochapack/lib/entry.js:3:1)
    at Array.forEach (<anonymous>)
    at Object../node_modules/@vue/cli-plugin-unit-mocha/node_modules/mochapack/lib/entry.js (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/node_modules/@vue/cli-plugin-unit-mocha/node_modules/mochapack/lib/entry.js:10:1)
    at __webpack_require__ (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/webpack/bootstrap:19:1)
    at /home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/webpack:/webpack/bootstrap:83:1
    at Object.<anonymous> (/home/amaury/Documents/web-projects/projet-restau/frontend/dist/js/main.js:87:10)
    at Module._compile (internal/modules/cjs/loader.js:1123:30)
    at Object._module2.default._extensions.<computed> [as .js] (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/@vue/cli-plugin-unit-mocha/node_modules/mochapack/src/util/registerRequireHook.js:99:12)
    at Module.load (internal/modules/cjs/loader.js:972:32)
    at Function.Module._load (internal/modules/cjs/loader.js:872:14)
    at Module.require (internal/modules/cjs/loader.js:1012:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at /home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/@vue/cli-plugin-unit-mocha/node_modules/mocha/lib/mocha.js:334:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/@vue/cli-plugin-unit-mocha/node_modules/mocha/lib/mocha.js:331:14)
    at Mocha.run (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/@vue/cli-plugin-unit-mocha/node_modules/mocha/lib/mocha.js:809:10)
    at cb (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/@vue/cli-plugin-unit-mocha/node_modules/mochapack/src/runner/TestRunner.js:96:21)
    at /home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/@vue/cli-plugin-unit-mocha/node_modules/mochapack/src/webpack/compiler/registerReadyCallback.js:12:7
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:61:1)
    at AsyncSeriesHook.lazyCompileHook (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/tapable/lib/Hook.js:154:20)
    at /home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/webpack/lib/Compiler.js:304:22
    at Compiler.emitRecords (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/webpack/lib/Compiler.js:499:39)
    at /home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/webpack/lib/Compiler.js:298:10
    at /home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/webpack/lib/Compiler.js:485:14
    at eval (eval at create (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)
    at /home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/copy-webpack-plugin/dist/index.js:115:7
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at AsyncSeriesHook.lazyCompileHook (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/tapable/lib/Hook.js:154:20)
    at /home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/webpack/lib/Compiler.js:482:27
    at /home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/neo-async/async.js:2818:7
    at done (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/neo-async/async.js:3522:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:4:1)
    at /home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/webpack/lib/Compiler.js:464:33
    at MemoryFileSystem.writeFile (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/memory-fs/lib/MemoryFileSystem.js:328:9)
    at writeOut (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/webpack/lib/Compiler.js:462:30)
    at Immediate._onImmediate (/home/amaury/Documents/web-projects/projet-restau/frontend/node_modules/memory-fs/lib/MemoryFileSystem.js:288:4)
    at processImmediate (internal/timers.js:456:21)
    at process.topLevelDomainCallback (domain.js:137:15)
4

0 に答える 0