debian-mirror-gitlab/spec/frontend/vue_shared/components/todo_button_spec.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { shallowMount, mount } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui';
import TodoButton from '~/vue_shared/components/todo_button.vue';
describe('Todo Button', () => {
let wrapper;
const createComponent = (props = {}, mountFn = shallowMount) => {
wrapper = mountFn(TodoButton, {
propsData: {
...props,
},
});
};
afterEach(() => {
wrapper.destroy();
});
it('renders GlButton', () => {
createComponent();
expect(wrapper.find(GlButton).exists()).toBe(true);
});
it('emits click event when clicked', () => {
createComponent({}, mount);
wrapper.find(GlButton).trigger('click');
expect(wrapper.emitted().click).toBeTruthy();
});
it.each`
label | isTodo
${'Mark as done'} | ${true}
2021-01-03 14:25:43 +05:30
${'Add a To Do'} | ${false}
2020-11-24 15:15:51 +05:30
`('sets correct label when isTodo is $isTodo', ({ label, isTodo }) => {
createComponent({ isTodo });
expect(wrapper.find(GlButton).text()).toBe(label);
});
it('binds additional props to GlButton', () => {
createComponent({ loading: true });
expect(wrapper.find(GlButton).props('loading')).toBe(true);
});
});