Check that stubbed component method is called

This commit is contained in:
mattwr18 2020-01-27 13:44:40 +01:00
parent 853ff9b92b
commit 36130d9d7c
2 changed files with 7 additions and 12 deletions

View File

@ -105,6 +105,7 @@ describe('CommentList.vue', () => {
beforeEach(() => { beforeEach(() => {
wrapper = Wrapper() wrapper = Wrapper()
}) })
it('Comment emitted reply()', () => { it('Comment emitted reply()', () => {
wrapper.find(Comment).vm.$emit('reply', { wrapper.find(Comment).vm.$emit('reply', {
id: 'commentAuthorId', id: 'commentAuthorId',

View File

@ -11,7 +11,7 @@ const localVue = global.localVue
localVue.directive('scrollTo', jest.fn()) localVue.directive('scrollTo', jest.fn())
describe('PostSlug', () => { describe('PostSlug', () => {
let store, propsData, mocks, stubs, wrapper, Wrapper, spy let store, propsData, mocks, stubs, wrapper, Wrapper
beforeEach(() => { beforeEach(() => {
store = new Vuex.Store({ store = new Vuex.Store({
@ -47,17 +47,9 @@ describe('PostSlug', () => {
query: jest.fn().mockResolvedValue({ data: { PostEmotionsCountByEmotion: {} } }), query: jest.fn().mockResolvedValue({ data: { PostEmotionsCountByEmotion: {} } }),
}, },
$scrollTo: jest.fn(), $scrollTo: jest.fn(),
$refs: {
editor: {
insertReply: jest.fn(),
},
commentForm: {
reply: jest.fn(),
},
},
} }
stubs = { stubs = {
HcEditor: { render: () => {}, methods: { insertReply: () => null } }, HcEditor: { render: () => {}, methods: { insertReply: jest.fn(() => null) } },
ContentViewer: true, ContentViewer: true,
} }
jest.useFakeTimers() jest.useFakeTimers()
@ -82,7 +74,6 @@ describe('PostSlug', () => {
}, },
ready: true, ready: true,
}) })
spy = jest.spyOn(wrapper.vm, 'reply')
}) })
describe('mount', () => { describe('mount', () => {
@ -126,7 +117,10 @@ describe('PostSlug', () => {
id: 'commentAuthorId', id: 'commentAuthorId',
slug: 'ogerly', slug: 'ogerly',
}) })
expect(spy).toHaveBeenCalledTimes(1) expect(stubs.HcEditor.methods.insertReply).toHaveBeenCalledWith({
id: 'commentAuthorId',
slug: 'ogerly',
})
}) })
}) })
}) })