swapnali42 / MealAssignment

This is practice assignment for learning VUE
0 stars 0 forks source link

Cannot read property 'destroy' of undefined #1

Open swapnali42 opened 3 years ago

swapnali42 commented 3 years ago

While testing project in vue js with jest. My code coverage was more than 90% before code converting into vuex but after converting code into vuex I got the following errors. help me for solving that issue

testing error

My mealDetails component as follow:

``

``

My myDetails.spec.js is as follows:

`import { shallowMount, createLocalVue } from '@vue/test-utils' import MealDetails from '@/components/MealDetails.vue' import BootstrapVue from 'bootstrap-vue' import Vuex from 'vuex';

describe('in a MealDetails component', () => { let wrapper;

const state = { mealDetails: { strMeal:'Sugar Pie', strMealThumb:'https://www.themealdb.com/images/media/meals/yrstur1511816601.jpg', strCategory:'Dessert', strArea:'Canadian', idMeal:'52931', }, };

const actions = { getMealDetailsById: jest.fn(), }; beforeEach(() => { const localVue = createLocalVue(); localVue.use(BootstrapVue); localVue.use(Vuex);

const store = new Vuex.store({
  state,

  actions,
});
wrapper = shallowMount(MealDetails, {
  localVue,
  store,

  mocks: {
    $route: {
      params: {id:'52931'}
    },
  },
});

});

afterEach(() => { wrapper.destroy(); });

it('is a vue instance', () => { expect(wrapper.isVueInstance).toBeTruthy(); });

it('should render the correct markup', () => { expect(wrapper.html()).toContain('

'); }); it('should render the correct p tag', () => { expect(wrapper.html()).toContain('

'); }); it('getMealDetailsById action should be called on calling getMealDetailsById method', () => { wrapper.vm.getMealDetailsById('52856'); expect(actions.getMealDetailsById).toHaveBeenCalled(); });

});`

swapnali42 commented 3 years ago

no one is here for solving this issue