mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Asserts error messages on tests
This commit is contained in:
@@ -3,14 +3,18 @@ import ClipboardAction from '../src/clipboard-action';
|
|||||||
describe('ClipboardAction', () => {
|
describe('ClipboardAction', () => {
|
||||||
before(() => {
|
before(() => {
|
||||||
global.target = document.createElement('input');
|
global.target = document.createElement('input');
|
||||||
target.setAttribute('id', 'foo');
|
global.target.setAttribute('id', 'target');
|
||||||
document.body.appendChild(global.target);
|
document.body.appendChild(global.target);
|
||||||
|
|
||||||
global.trigger = document.createElement('button');
|
global.trigger = document.createElement('button');
|
||||||
trigger.setAttribute('class', 'btn');
|
global.trigger.setAttribute('class', 'btn');
|
||||||
document.body.appendChild(global.trigger);
|
document.body.appendChild(global.trigger);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
document.body.innerHTML = '';
|
||||||
|
});
|
||||||
|
|
||||||
describe('#constructor', () => {
|
describe('#constructor', () => {
|
||||||
it('should throw an error since both "data-text" and "data-target" were passed', (done) => {
|
it('should throw an error since both "data-text" and "data-target" were passed', (done) => {
|
||||||
try {
|
try {
|
||||||
@@ -40,10 +44,12 @@ describe('ClipboardAction', () => {
|
|||||||
it('should throw an error since "data-action" is invalid', (done) => {
|
it('should throw an error since "data-action" is invalid', (done) => {
|
||||||
try {
|
try {
|
||||||
new ClipboardAction({
|
new ClipboardAction({
|
||||||
|
text: 'foo',
|
||||||
action: 'paste'
|
action: 'paste'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
|
assert.equal(e.message, 'Invalid "data-action" value, use either "copy" or "cut"');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -51,17 +57,13 @@ describe('ClipboardAction', () => {
|
|||||||
it('should throw an error since "data-target" do not match any element', (done) => {
|
it('should throw an error since "data-target" do not match any element', (done) => {
|
||||||
try {
|
try {
|
||||||
new ClipboardAction({
|
new ClipboardAction({
|
||||||
target: 'zzz',
|
target: 'foo'
|
||||||
trigger: global.trigger
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
|
assert.equal(e.message, 'Invalid "data-target" selector, use a value that matches an ID');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
|
||||||
document.body.innerHTML = '';
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ describe('Clipboard', () => {
|
|||||||
new Clipboard();
|
new Clipboard();
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
|
assert.equal(e.message, 'No matches were found for the provided selector');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -22,6 +23,7 @@ describe('Clipboard', () => {
|
|||||||
new Clipboard('#abc');
|
new Clipboard('#abc');
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
|
assert.equal(e.message, 'No matches were found for the provided selector');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user