Asserts error messages on tests

This commit is contained in:
Zeno Rocha 2015-09-26 09:26:54 -07:00
parent abeee82bdc
commit 1acd23049e
2 changed files with 12 additions and 8 deletions

View File

@ -3,14 +3,18 @@ import ClipboardAction from '../src/clipboard-action';
describe('ClipboardAction', () => {
before(() => {
global.target = document.createElement('input');
target.setAttribute('id', 'foo');
global.target.setAttribute('id', 'target');
document.body.appendChild(global.target);
global.trigger = document.createElement('button');
trigger.setAttribute('class', 'btn');
global.trigger.setAttribute('class', 'btn');
document.body.appendChild(global.trigger);
});
after(() => {
document.body.innerHTML = '';
});
describe('#constructor', () => {
it('should throw an error since both "data-text" and "data-target" were passed', (done) => {
try {
@ -40,10 +44,12 @@ describe('ClipboardAction', () => {
it('should throw an error since "data-action" is invalid', (done) => {
try {
new ClipboardAction({
text: 'foo',
action: 'paste'
});
}
catch(e) {
assert.equal(e.message, 'Invalid "data-action" value, use either "copy" or "cut"');
done();
}
});
@ -51,17 +57,13 @@ describe('ClipboardAction', () => {
it('should throw an error since "data-target" do not match any element', (done) => {
try {
new ClipboardAction({
target: 'zzz',
trigger: global.trigger
target: 'foo'
});
}
catch(e) {
assert.equal(e.message, 'Invalid "data-target" selector, use a value that matches an ID');
done();
}
});
});
after(() => {
document.body.innerHTML = '';
});
});

View File

@ -13,6 +13,7 @@ describe('Clipboard', () => {
new Clipboard();
}
catch(e) {
assert.equal(e.message, 'No matches were found for the provided selector');
done();
}
});
@ -22,6 +23,7 @@ describe('Clipboard', () => {
new Clipboard('#abc');
}
catch(e) {
assert.equal(e.message, 'No matches were found for the provided selector');
done();
}
});