lawliet
4 months ago
101
0
Vue

Window.app TypeError: Cannot read property ‘context’ of undefined

Posted 4 months ago by lawliet

Dear All ,

I am trying to mount a component in test file using vue test util. I am getting a below error right after the below import statement.

import { mount, createLocalVue } from '@vue/test-utils'
// this import statement is throwing the error.
import handshake from "../../../../client/js/components/handshake.vue";
import VueRouter from 'vue-router';
import Vuelidate from 'vuelidate';
import VeeValidate from 'vee-validate';
import Vue from 'vue';


const localVue = createLocalVue();
localVue.use(VueRouter);
Vue.use(Vuelidate); 


describe('Hand shake Test Suite1',()=>{
it('snapshot testing',()=>{
    const router = new VueRouter();         
    const wrapper =mount(handshake);
     
});

});

Below error is thrown in the console .

 ? Test suite failed to run

   TypeError: Cannot read property 'context' of undefined

      5 | const context = Object.assign({
      6 |   csrfToken: null
   >  7 | }, window.app.context);
        |               ^
      8 |
      9 | export default context;
     10 |

     at Object.context (client/js/context.js:7:15)
     at Object.<anonymous> (client/js/models/handhshake-workflow-model-validations
js:7:1)
     at client/js/components/handhshake.vue:281:1
     at Object.<anonymous> (client/js/components/handhshake:355:3)
     at Object.<anonymous> (test/unit/client/components/handhshake.test.js:2:

When I reviewed the vue file, it is importing a js file for one of its data and it that js file window.app is being called. This is where the error is coming from.

'use strict';

// These properties will be set from window.app.context, which is set by the server side
// You can see how the server sets this value in: $/server/startup/handlebars.js
const context = Object.assign({
  csrfToken: null
}, window.app.context);

export default context;

I am not sure how to make this Window.app visible in my test file or is there any other way to get around it. Can anyone please help me.

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