From e5d3f91f354e8283735d649eb4e8cab24058a24f Mon Sep 17 00:00:00 2001 From: Beto Muniz Date: Wed, 20 Jan 2021 12:57:58 -0300 Subject: [PATCH 1/2] Remove unnecessary dependency --- test/clipboard.js | 102 ++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/test/clipboard.js b/test/clipboard.js index 7a3b235..bb6a7ae 100644 --- a/test/clipboard.js +++ b/test/clipboard.js @@ -1,127 +1,131 @@ -import Clipboard from '../src/clipboard'; -import ClipboardAction from '../src/clipboard-action'; -import listen from 'good-listener'; +import Clipboard from "../src/clipboard"; +import ClipboardAction from "../src/clipboard-action"; -describe('Clipboard', () => { +describe("Clipboard", () => { before(() => { - global.button = document.createElement('button'); - global.button.setAttribute('class', 'btn'); - global.button.setAttribute('data-clipboard-text', 'foo'); + global.button = document.createElement("button"); + global.button.setAttribute("class", "btn"); + global.button.setAttribute("data-clipboard-text", "foo"); document.body.appendChild(global.button); - global.span = document.createElement('span'); - global.span.innerHTML = 'bar'; + global.span = document.createElement("span"); + global.span.innerHTML = "bar"; global.button.appendChild(span); global.event = { target: global.button, - currentTarget: global.button + currentTarget: global.button, }; }); after(() => { - document.body.innerHTML = ''; + document.body.innerHTML = ""; }); - describe('#resolveOptions', () => { + describe("#resolveOptions", () => { before(() => { global.fn = () => {}; }); - it('should set action as a function', () => { - let clipboard = new Clipboard('.btn', { - action: global.fn + it("should set action as a function", () => { + let clipboard = new Clipboard(".btn", { + action: global.fn, }); assert.equal(global.fn, clipboard.action); }); - it('should set target as a function', () => { - let clipboard = new Clipboard('.btn', { - target: global.fn + it("should set target as a function", () => { + let clipboard = new Clipboard(".btn", { + target: global.fn, }); assert.equal(global.fn, clipboard.target); }); - it('should set text as a function', () => { - let clipboard = new Clipboard('.btn', { - text: global.fn + it("should set text as a function", () => { + let clipboard = new Clipboard(".btn", { + text: global.fn, }); assert.equal(global.fn, clipboard.text); }); - it('should set container as an object', () => { - let clipboard = new Clipboard('.btn', { - container: document.body + it("should set container as an object", () => { + let clipboard = new Clipboard(".btn", { + container: document.body, }); assert.equal(document.body, clipboard.container); }); - it('should set container as body by default', () => { - let clipboard = new Clipboard('.btn'); + it("should set container as body by default", () => { + let clipboard = new Clipboard(".btn"); assert.equal(document.body, clipboard.container); }); }); - describe('#listenClick', () => { - it('should add a click event listener to the passed selector', () => { - let clipboard = new Clipboard('.btn'); + describe("#listenClick", () => { + it("should add a click event listener to the passed selector", () => { + let clipboard = new Clipboard(".btn"); assert.isObject(clipboard.listener); }); }); - describe('#onClick', () => { - it('should create a new instance of ClipboardAction', () => { - let clipboard = new Clipboard('.btn'); + describe("#onClick", () => { + it("should create a new instance of ClipboardAction", () => { + let clipboard = new Clipboard(".btn"); clipboard.onClick(global.event); assert.instanceOf(clipboard.clipboardAction, ClipboardAction); }); - it('should use an event\'s currentTarget when not equal to target', () => { - let clipboard = new Clipboard('.btn'); - let bubbledEvent = { target: global.span, currentTarget: global.button }; + it("should use an event's currentTarget when not equal to target", () => { + let clipboard = new Clipboard(".btn"); + let bubbledEvent = { + target: global.span, + currentTarget: global.button, + }; clipboard.onClick(bubbledEvent); assert.instanceOf(clipboard.clipboardAction, ClipboardAction); }); - it('should throw an exception when target is invalid', done => { + it("should throw an exception when target is invalid", (done) => { try { - const clipboard = new Clipboard('.btn', { + const clipboard = new Clipboard(".btn", { target() { return null; - } + }, }); clipboard.onClick(global.event); - } - catch(e) { - assert.equal(e.message, 'Invalid "target" value, use a valid Element'); + } catch (e) { + assert.equal( + e.message, + 'Invalid "target" value, use a valid Element' + ); done(); } }); }); - describe('#static isSupported', () => { - it('should return the support of the given action', () => { - assert.equal(Clipboard.isSupported('copy'), true); - assert.equal(Clipboard.isSupported('cut'), true); + describe("#static isSupported", () => { + it("should return the support of the given action", () => { + assert.equal(Clipboard.isSupported("copy"), true); + assert.equal(Clipboard.isSupported("cut"), true); }); - it('should return the support of the cut and copy actions', () => { + it("should return the support of the cut and copy actions", () => { assert.equal(Clipboard.isSupported(), true); }); }); - describe('#destroy', () => { - it('should destroy an existing instance of ClipboardAction', () => { - let clipboard = new Clipboard('.btn'); + describe("#destroy", () => { + it("should destroy an existing instance of ClipboardAction", () => { + let clipboard = new Clipboard(".btn"); clipboard.onClick(global.event); clipboard.destroy(); From d9b90c2f5d25a9752093b7f2fb0ec990250fa16a Mon Sep 17 00:00:00 2001 From: Beto Muniz Date: Wed, 20 Jan 2021 12:58:11 -0300 Subject: [PATCH 2/2] Add node version control to the project --- .nvmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..8351c19 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +14