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(() => {
wrapper = Wrapper()
})
it('Comment emitted reply()', () => {
wrapper.find(Comment).vm.$emit('reply', {
id: 'commentAuthorId',

View File

@ -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',
})
})
})
})