Skip to content

Instantly share code, notes, and snippets.

@Jones-S
Created November 20, 2019 00:32
Show Gist options
  • Save Jones-S/2d92501a4f19adee296b9cc1ea3ba857 to your computer and use it in GitHub Desktop.
Save Jones-S/2d92501a4f19adee296b9cc1ea3ba857 to your computer and use it in GitHub Desktop.
Vue testing file
import { shallowMount } from '@vue/test-utils';
import jest from 'jest-mock';
import StoreFinderMap from '../../src/modules/StoreFinder/components/StoreFinderMap/StoreFinderMap.vue';
describe('StoreFinderMap', () => {
let wrapper;
beforeEach(() => {
const initMapMock = jest.fn();
const initMarkersMock = jest.fn();
const subscribeToMapScrollMock = jest.fn();
wrapper = shallowMount(StoreFinderMap, {
// pass in some required props, with dummy content
propsData: {
google: {},
markerClusterStyle: ['markerClusterStyleMock'],
mapOptions: {},
},
// override methods which are called on mounted
methods: {
initMap: initMapMock,
initMarkers: initMarkersMock,
subscribeToMapScroll: subscribeToMapScrollMock,
},
computed: {
searchCoordinates: jest.fn(),
mapCoordinates: jest.fn(),
activeLocation: jest.fn(),
storeFilter: jest.fn(),
},
});
jest.clearAllMocks();
});
test('If marker represents a searched location/current user location, it should show the result icon', () => {
wrapper.setData({ mapOptions: { iconPath: 'filepath/' } });
expect(wrapper.vm.iconType({ attributes: { isResult: true } })).toEqual(`${wrapper.vm.mapOptions.iconPath}storefinder-result.svg`);
});
test('Set new map bounds when search coordinates are changed in vuex store', () => {
const spy = jest.spyOn(wrapper.vm, 'setMapBounds');
wrapper.vm.searchCoordinates = jest.fn(() => 'lala');
expect(spy).toBeCalled();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment