jeudi 25 octobre 2018

can't import javascript file in vue test utils

I am testing one vue file which import Javascript file.

//unlockWallet.worker.js

import { Wallet, Configs } from '@/helpers';

function create(password) {
  const createdWallet = {};
  const wallet = new Wallet.generate();
  createdWallet.walletJson = wallet.toV3(password, {
    kdf: Configs.wallet.kdf,
    n: Configs.wallet.n
  });
  createdWallet.name = wallet.getV3Filename();
  return createdWallet;
}

onmessage = function(event) {
  if (event.data.type === 'createWallet') {
    const workerResult = create(event.data.data[0]);
    postMessage(workerResult);
  }
};

And PasswordModal.vue I import unlockWallet.worker.js file like this.

import Worker from '@/workers/unlockWallet.worker.js'

in PasswordModal.spec.js

import {shallowMount} from '@vue/test-utils'
import PasswordModal from '@/layouts/PasswordModal.vue';

And I had failed to pass through this test.

Test suite failed to run ReferenceError: onmessage is not defined

Aucun commentaire:

Enregistrer un commentaire