diff --git a/src/clipboard.js b/src/clipboard.js index 79c1d07..f68f3ad 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -14,6 +14,10 @@ class Clipboard extends Emitter { constructor(selector) { super(); + if (!document.querySelectorAll(selector).length) { + throw new Error('No matches were found for the provided selector'); + } + delegate.bind(document.body, selector, 'click', (e) => this.initialize(e)); } diff --git a/test/clipboard-action.js b/test/clipboard-action.js index 9d48d15..d6a2d10 100644 --- a/test/clipboard-action.js +++ b/test/clipboard-action.js @@ -14,7 +14,7 @@ describe('ClipboardAction', () => { describe('#constructor', () => { it('should throw an error since "data-action" is invalid', (done) => { try { - new Clipboard({ + new ClipboardAction({ action: 'paste' }); }