From 36130d9d7c4995d956127c053ce2246cb2ddfc90 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Mon, 27 Jan 2020 13:44:40 +0100 Subject: [PATCH] Check that stubbed component method is called --- .../components/CommentList/CommentList.spec.js | 1 + webapp/pages/post/_id/_slug/index.spec.js | 18 ++++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/webapp/components/CommentList/CommentList.spec.js b/webapp/components/CommentList/CommentList.spec.js index 02d2f2f42..ac7b88c0e 100644 --- a/webapp/components/CommentList/CommentList.spec.js +++ b/webapp/components/CommentList/CommentList.spec.js @@ -105,6 +105,7 @@ describe('CommentList.vue', () => { beforeEach(() => { wrapper = Wrapper() }) + it('Comment emitted reply()', () => { wrapper.find(Comment).vm.$emit('reply', { id: 'commentAuthorId', diff --git a/webapp/pages/post/_id/_slug/index.spec.js b/webapp/pages/post/_id/_slug/index.spec.js index 2ae34b15e..6c5cb5259 100644 --- a/webapp/pages/post/_id/_slug/index.spec.js +++ b/webapp/pages/post/_id/_slug/index.spec.js @@ -11,7 +11,7 @@ const localVue = global.localVue localVue.directive('scrollTo', jest.fn()) describe('PostSlug', () => { - let store, propsData, mocks, stubs, wrapper, Wrapper, spy + let store, propsData, mocks, stubs, wrapper, Wrapper beforeEach(() => { store = new Vuex.Store({ @@ -47,17 +47,9 @@ describe('PostSlug', () => { query: jest.fn().mockResolvedValue({ data: { PostEmotionsCountByEmotion: {} } }), }, $scrollTo: jest.fn(), - $refs: { - editor: { - insertReply: jest.fn(), - }, - commentForm: { - reply: jest.fn(), - }, - }, } stubs = { - HcEditor: { render: () => {}, methods: { insertReply: () => null } }, + HcEditor: { render: () => {}, methods: { insertReply: jest.fn(() => null) } }, ContentViewer: true, } jest.useFakeTimers() @@ -82,7 +74,6 @@ describe('PostSlug', () => { }, ready: true, }) - spy = jest.spyOn(wrapper.vm, 'reply') }) describe('mount', () => { @@ -126,7 +117,10 @@ describe('PostSlug', () => { id: 'commentAuthorId', slug: 'ogerly', }) - expect(spy).toHaveBeenCalledTimes(1) + expect(stubs.HcEditor.methods.insertReply).toHaveBeenCalledWith({ + id: 'commentAuthorId', + slug: 'ogerly', + }) }) }) })