-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
58 additions
and
169 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,58 @@ | ||
import { render, fireEvent } from '@testing-library/vue' | ||
import { shallowMount, mount } from '@vue/test-utils' | ||
import Button from './Button.vue' | ||
|
||
describe('Button.vue', () => { | ||
let wrapper | ||
|
||
describe('Button', () => { | ||
beforeEach(() => { | ||
wrapper = shallowMount(Button) | ||
}) | ||
|
||
it('is called', () => { | ||
expect(wrapper.exists()).toBeTruthy() | ||
}) | ||
|
||
it('render correctly', () => { | ||
expect(render(Button).html()).toMatchSnapshot() | ||
expect(wrapper.html()).toMatchSnapshot() | ||
}) | ||
|
||
it('emit a click event', async () => { | ||
const handleClick = jest.fn() | ||
const wrapper = render(<Button onClick={handleClick}>Click Me</Button>) | ||
await fireEvent.click(wrapper.getByText(/click me/i)) | ||
expect(handleClick).toHaveBeenCalledTimes(1) | ||
it('emit a click event', () => { | ||
wrapper = mount(Button) | ||
wrapper.find('button').trigger('click') | ||
expect(wrapper.emitted()).toHaveProperty('click') | ||
}) | ||
it('should be medium', async () => { | ||
wrapper.setProps({ | ||
size: 'is-medium', | ||
}) | ||
await wrapper.vm.$nextTick() | ||
expect(wrapper.classes()).toContain('is-medium') | ||
}) | ||
it('should be medium', () => { | ||
const wrapper = render(Button, { props: { label: 'medium', size: 'is-medium' } }) | ||
|
||
expect(wrapper.getByRole('button', { name: /medium/i })).toHaveClass('is-medium') | ||
it('should be rounded when prop is set to true', async () => { | ||
wrapper.setProps({ | ||
rounded: true, | ||
}) | ||
await wrapper.vm.$nextTick() | ||
expect(wrapper.classes()).toContain('is-rounded') | ||
}) | ||
it('should be rounded when prop is set to true', () => { | ||
const wrapper = render(Button, { props: { label: 'rounded', rounded: true } }) | ||
|
||
expect(wrapper.getByRole('button', { name: /rounded/i })).toHaveClass('is-rounded') | ||
it('should set tag to "button" if disabled', () => { | ||
wrapper = shallowMount(Button, { | ||
props: { | ||
tag: 'a', | ||
}, | ||
}) | ||
expect(wrapper.vm.computedTag).toBe('a') | ||
|
||
wrapper = shallowMount(Button, { | ||
props: { | ||
tag: 'a', | ||
}, | ||
attrs: { | ||
disabled: true, | ||
}, | ||
}) | ||
expect(wrapper.vm.computedTag).toBe('button') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/components/primitives/Button/__snapshots__/Button.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters