Skip to content

Issue #34 - Unit and e2e tests for CopyButton component #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 7, 2019
Prev Previous commit
Next Next commit
Moving unit test file to 'components' directory
  • Loading branch information
priscilauchoa committed Oct 3, 2019
commit 6988a2801391f1b3c8a0102e3dc68b41e1f090a4
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CopyButton from '@/components/CopyButton.vue'
import { doesNotThrow } from 'assert';

const DOM_SOURCE_ID = 'el-test';
const DOM_SOURCE_VALUE = 'test clipboard value'

// mock dom source
function _mockDOMSource(value) {
Expand All @@ -29,9 +30,8 @@ function _mockDomMethodsForClipboardJS(value) {
}

beforeEach(() => {
const domValue = 'test clipboard value'
_mockDOMSource(domValue)
_mockDomMethodsForClipboardJS(domValue)
_mockDOMSource(DOM_SOURCE_VALUE)
_mockDomMethodsForClipboardJS(DOM_SOURCE_VALUE)
})

describe('CopyButton.vue', () => {
Expand All @@ -48,12 +48,25 @@ describe('CopyButton.vue', () => {
expect(wrapper.text()).toBe(slots.default);
})

it('should change the text when clicked to Copied and 2 seconds after that come back to original text', done => {
it('should change the text when clicked to \'Copied!\' and 2 secs later swich back to the original text', done => {
wrapper.trigger('click');
expect(wrapper.text()).toBe('Copied!');
setTimeout(() => {
expect(wrapper.text()).toBe(slots.default);
done();
}, 2000);
})

it('Testing button success', () => {
wrapper.trigger('click');
expect(wrapper.emitted().copied).toBeTruthy();
})

it('Testing value return of button when it have success', () => {
wrapper.trigger('click');
expect(wrapper.text()).toBe('Copied!');
})
})