diff --git a/packages/vue/__tests__/Mixin/Collection.test.js b/packages/vue/__tests__/Mixin/Collection.test.js index c32089e..decfd5b 100644 --- a/packages/vue/__tests__/Mixin/Collection.test.js +++ b/packages/vue/__tests__/Mixin/Collection.test.js @@ -124,4 +124,23 @@ describe('The Collection mixin', () => { expect(mixin.$store.getters['hyral_product/collection']).not.toHaveBeenCalled(); }); + + test('that the mixin doesn\'t initialize if the component does not define the collectionName or resourceType', () => { + const mixin = Object.assign({ + initCollection: jest.fn(), + loadCollection: jest.fn(), + }, collectionMixin); + + mixin.serverPrefetch(); + expect(mixin.initCollection).not.toHaveBeenCalled(); + expect(mixin.loadCollection).not.toHaveBeenCalled(); + + mixin.mounted(); + expect(mixin.initCollection).not.toHaveBeenCalled(); + expect(mixin.loadCollection).not.toHaveBeenCalled(); + + mixin.created(); + expect(mixin.initCollection).not.toHaveBeenCalled(); + expect(mixin.loadCollection).not.toHaveBeenCalled(); + }); }); diff --git a/packages/vue/src/Mixin/Collection.js b/packages/vue/src/Mixin/Collection.js index 9f8fc21..bd20aa0 100644 --- a/packages/vue/src/Mixin/Collection.js +++ b/packages/vue/src/Mixin/Collection.js @@ -15,6 +15,10 @@ export default { }, }, created() { + if (!this.collectionName || !this.resourceType) { + return; + } + this.initCollection(); }, /**