mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Throws error if either data-target or data-text were passed and throws error if neither data-target nor data-text were passed too
This commit is contained in:
parent
ce7b9652c7
commit
abeee82bdc
@ -8,19 +8,25 @@ class ClipboardAction {
|
||||
*/
|
||||
constructor(options) {
|
||||
this.action = options.action;
|
||||
this.emitter = options.emitter;
|
||||
this.emitter = options.emitter;
|
||||
this.target = options.target;
|
||||
this.text = options.text;
|
||||
this.trigger = options.trigger;
|
||||
|
||||
this.selectedText = '';
|
||||
|
||||
if (this.text) {
|
||||
if (this.text && this.target) {
|
||||
throw new Error('Multiple attributes declared, use either "data-target" or "data-text"');
|
||||
}
|
||||
else if (this.text) {
|
||||
this.selectFake();
|
||||
}
|
||||
else if (this.target) {
|
||||
this.selectTarget();
|
||||
}
|
||||
else {
|
||||
throw new Error('Missing required attributes, use either "data-target" or "data-text"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,31 @@ describe('ClipboardAction', () => {
|
||||
});
|
||||
|
||||
describe('#constructor', () => {
|
||||
it('should throw an error since both "data-text" and "data-target" were passed', (done) => {
|
||||
try {
|
||||
new ClipboardAction({
|
||||
text: 'foo',
|
||||
target: 'target'
|
||||
});
|
||||
}
|
||||
catch(e) {
|
||||
assert.equal(e.message, 'Multiple attributes declared, use either "data-target" or "data-text"');
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error since neither "data-text" nor "data-target" were passed', (done) => {
|
||||
try {
|
||||
new ClipboardAction({
|
||||
action: ''
|
||||
});
|
||||
}
|
||||
catch(e) {
|
||||
assert.equal(e.message, 'Missing required attributes, use either "data-target" or "data-text"');
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error since "data-action" is invalid', (done) => {
|
||||
try {
|
||||
new ClipboardAction({
|
||||
|
Loading…
Reference in New Issue
Block a user