From 0035a9efe5d42cbb55bdccf054ebd4f04b5df92b Mon Sep 17 00:00:00 2001 From: coreycosman Date: Mon, 24 Dec 2018 00:31:43 +0400 Subject: [PATCH 1/3] add specs for update method and value watcher --- CHANGELOG.md | 1 + .../components/common/TmFieldSeed.spec.js | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0897a3119..72f8521b86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added compatibility to Gaia/SDK version 0.28.0-rc2 @faboweb - [\#1673](https://github.com/cosmos/voyager/issues/1673) Documentation and single command to run one or all tests with fallback for end to end test @sabau - [\#1683](https://github.com/cosmos/voyager/issues/1683) Governance: block voting twice for the same option @sabau +- [\#1774](https://github.com/cosmos/voyager/issues/1774) added specs for the TmFieldSeed update method and value watcher @coreycosman ### Changed diff --git a/test/unit/specs/components/common/TmFieldSeed.spec.js b/test/unit/specs/components/common/TmFieldSeed.spec.js index 3e5aa48d67..de0c46ca08 100644 --- a/test/unit/specs/components/common/TmFieldSeed.spec.js +++ b/test/unit/specs/components/common/TmFieldSeed.spec.js @@ -1,6 +1,8 @@ import { mount } from "@vue/test-utils" import htmlBeautify from "html-beautify" import TmFieldSeed from "common/TmFieldSeed" +import autosize from "autosize" +const spy = jest.spyOn(autosize, `update`) describe(`TmFieldSeed`, () => { let wrapper @@ -26,4 +28,22 @@ describe(`TmFieldSeed`, () => { it(`has the correct class`, () => { expect(wrapper.find(`.tm-field`).classes()).toContain(`tm-field-seed`) }) + + it(`emits input event on update method call`, () => { + wrapper.vm.update(`test event`) + expect(wrapper.emitted().input[0][0]).toEqual(`test event`) + }) + + it(`does not emit input event when update method not called`, () => { + expect(wrapper.emitted()).toEqual({}) + }) + it(`does not call autosize.update when value does not changes`, async () => { + expect(spy.mock.calls).toEqual([]) + }) + it(`calls autosize.update when value changes`, async () => { + wrapper.setProps({ value: `change value` }) + await wrapper.vm.$nextTick() + expect(spy).toBeCalled() + expect(spy.mock.calls[0].length).toEqual(1) + }) }) From 5c75ce0181faae8cc0b2d28f5aa1a78549f6e515 Mon Sep 17 00:00:00 2001 From: coreycosman Date: Mon, 24 Dec 2018 00:48:00 +0400 Subject: [PATCH 2/3] change issue # and CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72f8521b86..0ec92d2758 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,7 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added compatibility to Gaia/SDK version 0.28.0-rc2 @faboweb - [\#1673](https://github.com/cosmos/voyager/issues/1673) Documentation and single command to run one or all tests with fallback for end to end test @sabau - [\#1683](https://github.com/cosmos/voyager/issues/1683) Governance: block voting twice for the same option @sabau -- [\#1774](https://github.com/cosmos/voyager/issues/1774) added specs for the TmFieldSeed update method and value watcher @coreycosman +- [\#1774](https://github.com/cosmos/voyager/issues/1776) added specs for the TmFieldSeed update method and value watcher @coreycosman ### Changed From d43efc79424f7d8a812dbeb033c356bc8a7b638b Mon Sep 17 00:00:00 2001 From: coreycosman Date: Tue, 8 Jan 2019 19:30:40 +0400 Subject: [PATCH 3/3] move spy and autosize to respective blocks --- test/unit/specs/components/common/TmFieldSeed.spec.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unit/specs/components/common/TmFieldSeed.spec.js b/test/unit/specs/components/common/TmFieldSeed.spec.js index de0c46ca08..366b679adb 100644 --- a/test/unit/specs/components/common/TmFieldSeed.spec.js +++ b/test/unit/specs/components/common/TmFieldSeed.spec.js @@ -1,8 +1,6 @@ import { mount } from "@vue/test-utils" import htmlBeautify from "html-beautify" import TmFieldSeed from "common/TmFieldSeed" -import autosize from "autosize" -const spy = jest.spyOn(autosize, `update`) describe(`TmFieldSeed`, () => { let wrapper @@ -38,9 +36,13 @@ describe(`TmFieldSeed`, () => { expect(wrapper.emitted()).toEqual({}) }) it(`does not call autosize.update when value does not changes`, async () => { + const autosize = require(`autosize`) + const spy = jest.spyOn(autosize, `update`) expect(spy.mock.calls).toEqual([]) }) it(`calls autosize.update when value changes`, async () => { + const autosize = require(`autosize`) + const spy = jest.spyOn(autosize, `update`) wrapper.setProps({ value: `change value` }) await wrapper.vm.$nextTick() expect(spy).toBeCalled()