Skip to content

Commit

Permalink
test(snackbar): test event of snackbar component
Browse files Browse the repository at this point in the history
  • Loading branch information
BeADre committed May 18, 2021
1 parent c47aee2 commit 34794ea
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion packages/varlet-ui/src/snackbar/__tests__/component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import VarSnackbar from '../Snackbar'
import example from '../example'
import { mount } from '@vue/test-utils'
import { createApp } from 'vue'
import { delay } from '../../utils/jest'
import { delay, mockStubs } from '../../utils/jest'

test('test snackbar example', () => {
const wrapper = mount(example)
Expand Down Expand Up @@ -50,3 +50,47 @@ test('test snackbar style', async () => {
await delay(500)
expect(document.querySelector('.var-snackbar').style.display).toBe('none')
})

test('test snackbar event', async () => {
const open = jest.fn()
const opened = jest.fn()
const close = jest.fn()
const closed = jest.fn()
const { mockRestore } = mockStubs()

const template = `
<var-snackbar v-model:show="show" @open="open" @opened="opened" @close="close" @closed="closed">
Snackbar
</var-snackbar>`

const wrapper = mount({
components: {
[VarSnackbar.name]: VarSnackbar
},
data() {
return {
show: false
}
},
methods: {
open,
opened,
close,
closed
},
template,
})

await delay(0)
await wrapper.setData({ show: true })
await delay(200)
await wrapper.setData({ show: false })
await delay(200)

expect(open).toHaveBeenCalledTimes(1)
expect(opened).toHaveBeenCalledTimes(1)
expect(close).toHaveBeenCalledTimes(1)
expect(closed).toHaveBeenCalledTimes(1)

mockRestore()
})

0 comments on commit 34794ea

Please sign in to comment.