mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Removes error message when target/text attributes are null, undefined, or false
This commit is contained in:
parent
0163f7cb72
commit
7a5a910bcd
@ -32,18 +32,12 @@ class ClipboardAction {
|
|||||||
* on the existence of `text` and `target` properties.
|
* on the existence of `text` and `target` properties.
|
||||||
*/
|
*/
|
||||||
initSelection() {
|
initSelection() {
|
||||||
if (this.text && this.target) {
|
if (this.text) {
|
||||||
throw new Error('Multiple attributes declared, use either "target" or "text"');
|
|
||||||
}
|
|
||||||
else if (this.text) {
|
|
||||||
this.selectFake();
|
this.selectFake();
|
||||||
}
|
}
|
||||||
else if (this.target) {
|
else if (this.target) {
|
||||||
this.selectTarget();
|
this.selectTarget();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
throw new Error('Missing required attributes, use either "target" or "text"');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,29 +35,6 @@ describe('ClipboardAction', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#initSelection', () => {
|
describe('#initSelection', () => {
|
||||||
it('should throw an error since both "text" and "target" were passed', done => {
|
|
||||||
try {
|
|
||||||
new ClipboardAction({
|
|
||||||
text: 'foo',
|
|
||||||
target: document.querySelector('#input')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
assert.equal(e.message, 'Multiple attributes declared, use either "target" or "text"');
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error since neither "text" nor "target" were passed', done => {
|
|
||||||
try {
|
|
||||||
new ClipboardAction();
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
assert.equal(e.message, 'Missing required attributes, use either "target" or "text"');
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set the position right style property', done => {
|
it('should set the position right style property', done => {
|
||||||
// Set document direction
|
// Set document direction
|
||||||
document.documentElement.setAttribute('dir', 'rtl');
|
document.documentElement.setAttribute('dir', 'rtl');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user