koel/resources/assets/js/components/user/UserBadge.spec.ts

28 lines
788 B
TypeScript
Raw Normal View History

import UnitTestCase from '@/__tests__/UnitTestCase'
import factory from '@/__tests__/factory'
import { expect, it } from 'vitest'
import { eventBus } from '@/utils'
import { fireEvent } from '@testing-library/vue'
import UserBadge from './UserBadge.vue'
new class extends UnitTestCase {
private renderComponent () {
return this.actingAs(factory<User>('user', {
name: 'John Doe'
})).render(UserBadge)
}
protected test () {
it('renders', () => expect(this.renderComponent().html()).toMatchSnapshot())
it('logs out', async () => {
2022-07-22 16:27:29 +00:00
const emitMock = this.mock(eventBus, 'emit')
const { getByTestId } = this.renderComponent()
await fireEvent.click(getByTestId('btn-logout'))
2022-07-22 16:27:29 +00:00
expect(emitMock).toHaveBeenCalledWith('LOG_OUT')
})
}
}