diff --git a/README.md b/README.md index b757952..147435d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,12 @@ $ npm install vue-input-autosize --save ## Usage -Coming soon... +```js +import Vue from "vue"; +import VueInputAutosize from "vue-input-autosize"; + +Vue.use(VueInputAutosize, { maxWidth: 500, minWidth: 20, comfortZone: 0 }); +``` ## Development diff --git a/test/VueInputAutosize.spec.js b/test/VueInputAutosize.spec.js index d92e385..461e98f 100644 --- a/test/VueInputAutosize.spec.js +++ b/test/VueInputAutosize.spec.js @@ -4,88 +4,107 @@ import VueInputAutosize from "../src"; Vue.use(VueInputAutosize); describe("vue-input-autosize", () => { + it("has an install method for Vue.use()", () => { expect(typeof VueInputAutosize.install).toEqual("function"); }); it("creates the v-input-autosize directive", () => { const vm = new Vue({ - template: "", + template: "", }).$mount(); expect(typeof vm.$options.directives["input-autosize"]).toEqual("object"); }); - it("sets the proper width according to the content of the input", () => { + it("sets the proper width according to the content of the input", (done) => { const vm = new Vue({ - template: "" - }).$mount(); - setTimeout(() => { - expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(33); - done(); - }, 0) - }); - it("uses the placeholder if there's no content to determine the width", () => { - const vm = new Vue({ - template: "" - }).$mount(); - setTimeout(() => { - expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(33); - done(); - }, 0) - }); - it("increases the width of the input when text is added", () => { - const vm = new Vue({ - template: "", + el: document.body, + replace: false, + template: "", data(){ return { msg: "Hello" } } - }).$mount(); - setTimeout(() => { - vm.msg = "Hello World"; - expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(66); + }) + setTimeout(function(){ + expect( Math.round(parseInt(vm.$els.test.style.width, 10)) ).toEqual(26); + done(); }, 0); }); - it("decreases the width of the input when text is removed", () => { + it("uses the placeholder if there's no content to determine the width", (done) => { const vm = new Vue({ - template: "", + el: document.body, + replace: false, + template: "", + }) + setTimeout(() => { + expect( Math.round(parseInt(vm.$els.test.style.width, 10)) ).toEqual(26); + done(); + }, 0) + }); + it("increases the width of the input when text is added", (done) => { + const vm = new Vue({ + el: document.body, + replace: false, + template: "", data(){ return { msg: "Hello" } } - }).$mount(); + }) + vm.msg = "Hello World"; setTimeout(() => { - vm.msg = "Hey!"; - expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(30); + expect( Math.round(parseInt(vm.$els.test.style.width, 10)) ).toBeGreaterThan(26); done(); }, 0); }); - it("clamps the input's width to the max width option", () => { + it("decreases the width of the input when text is removed", (done) => { const vm = new Vue({ - template: "", + el: document.body, + replace: false, + template: "", + data(){ + return { + msg: "Hello" + } + } + }); + vm.msg = "Hey!"; + setTimeout(() => { + expect( Math.round(parseInt(vm.$els.test.style.width, 10)) ).toBeLessThan(26); + done(); + }, 0); + }); + it("clamps the input's width to the max width option", (done) => { + const vm = new Vue({ + el: document.body, + replace: false, + template: "", data(){ return { msg: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." } } - }).$mount(); + }); setTimeout(() => { - expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(500); + expect( Math.round(parseInt(vm.$els.test.style.width, 10)) ).toEqual(500); done(); }, 0); }); - it("clamps the input's width to the min width option", () => { + it("clamps the input's width to the min width option", (done) => { const vm = new Vue({ - template: "", + el: document.body, + replace: false, + template: "", data(){ return { msg: "Hi" } } - }).$mount(); + }); setTimeout(() => { - expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(20); + expect( Math.round(parseInt(vm.$els.test.style.width, 10)) ).toEqual(20); done(); }, 0); });