From 3d94b10f0969197f514509c55eac0a674cc19936 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 18 May 2018 10:10:17 +0800 Subject: [PATCH 1/3] test: add avatar badge icon modal unit test --- components/avatar/__tests__/Avatar.test.js | 14 +++++ components/badge/__tests__/index.test.js | 21 +++++++ .../__snapshots__/index.test.js.snap | 3 + components/icon/__tests__/index.test.js | 13 +++++ components/modal/__tests__/Modal.test.js | 56 +++++++++++++++++++ .../__snapshots__/Modal.test.js.snap | 54 ++++++++++++++++++ tests/setup.js | 2 + 7 files changed, 163 insertions(+) create mode 100644 components/avatar/__tests__/Avatar.test.js create mode 100644 components/badge/__tests__/index.test.js create mode 100644 components/icon/__tests__/__snapshots__/index.test.js.snap create mode 100644 components/icon/__tests__/index.test.js create mode 100644 components/modal/__tests__/Modal.test.js create mode 100644 components/modal/__tests__/__snapshots__/Modal.test.js.snap diff --git a/components/avatar/__tests__/Avatar.test.js b/components/avatar/__tests__/Avatar.test.js new file mode 100644 index 000000000..22f84e51a --- /dev/null +++ b/components/avatar/__tests__/Avatar.test.js @@ -0,0 +1,14 @@ +import { mount } from '@vue/test-utils' +import Avatar from '..' + +describe('Avatar Render', () => { + it('Render long string correctly', () => { + const wrapper = mount(Avatar, { + slots: { + default: 'TestString', + }, + }) + const children = wrapper.findAll('.ant-avatar-string') + expect(children.length).toBe(1) + }) +}) diff --git a/components/badge/__tests__/index.test.js b/components/badge/__tests__/index.test.js new file mode 100644 index 000000000..8d0e860d1 --- /dev/null +++ b/components/badge/__tests__/index.test.js @@ -0,0 +1,21 @@ +import { mount } from '@vue/test-utils' +import Badge from '../index' + +describe('Badge', () => { + test('badge dot not scaling count > 9', () => { + const badge = mount({ + render () { + return + }, + }) + expect(badge.findAll('.ant-card-multiple-words').length).toBe(0) + }) + test('badge dot not showing count == 0', () => { + const badge = mount({ + render () { + return + }, + }) + expect(badge.findAll('.ant-badge-dot').length).toBe(0) + }) +}) diff --git a/components/icon/__tests__/__snapshots__/index.test.js.snap b/components/icon/__tests__/__snapshots__/index.test.js.snap new file mode 100644 index 000000000..9e4b4b34d --- /dev/null +++ b/components/icon/__tests__/__snapshots__/index.test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Icon should render to a 1`] = ``; diff --git a/components/icon/__tests__/index.test.js b/components/icon/__tests__/index.test.js new file mode 100644 index 000000000..ded9afca7 --- /dev/null +++ b/components/icon/__tests__/index.test.js @@ -0,0 +1,13 @@ +import { mount } from '@vue/test-utils' +import Icon from '..' + +describe('Icon', () => { + it('should render to a ', () => { + const wrapper = mount({ + render (h) { + return + }, + }) + expect(wrapper.html()).toMatchSnapshot() + }) +}) diff --git a/components/modal/__tests__/Modal.test.js b/components/modal/__tests__/Modal.test.js new file mode 100644 index 000000000..eac2e7038 --- /dev/null +++ b/components/modal/__tests__/Modal.test.js @@ -0,0 +1,56 @@ +import { mount } from '@vue/test-utils' +import Modal from '..' + +const ModalTester = { + props: ['footer', 'visible'], + methods: { + getContainer () { + return this.$refs.container + }, + }, + + render () { + const modalProps = { + props: { + ...this.$props, + getContainer: this.getContainer, + }, + } + return ( +
+
+ + Here is content of Modal + +
+ ) + }, +} + +describe('Modal', () => { + it('render correctly', () => { + const wrapper = mount(ModalTester) + expect(wrapper.html()).toMatchSnapshot() + const wrapper1 = mount( + { + render () { + return + }, + } + ) + expect(wrapper1.html()).toMatchSnapshot() + }) + + it('render without footer', () => { + const wrapper = mount( + { + render () { + return + }, + } + ) + expect(wrapper.html()).toMatchSnapshot() + }) +}) diff --git a/components/modal/__tests__/__snapshots__/Modal.test.js.snap b/components/modal/__tests__/__snapshots__/Modal.test.js.snap new file mode 100644 index 000000000..891c81e17 --- /dev/null +++ b/components/modal/__tests__/__snapshots__/Modal.test.js.snap @@ -0,0 +1,54 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Modal render correctly 1`] = ` +
+
+ +
+`; + +exports[`Modal render correctly 2`] = ` +
+
+
+
+ +
+
+ +
+`; + +exports[`Modal render without footer 1`] = ` +
+
+
+
+ +
+
+ +
+`; diff --git a/tests/setup.js b/tests/setup.js index 42fbf73b0..def324f67 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -1,3 +1,5 @@ +import Vue from 'vue' +Vue.config.silent = true /* eslint-disable global-require */ if (typeof window !== 'undefined') { From 9f08fdb8565528cf78b05a7bfc299a8c778765ed Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 18 May 2018 11:31:06 +0800 Subject: [PATCH 2/3] test: update modal test --- components/modal/__tests__/Modal.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/modal/__tests__/Modal.test.js b/components/modal/__tests__/Modal.test.js index eac2e7038..67dae5b67 100644 --- a/components/modal/__tests__/Modal.test.js +++ b/components/modal/__tests__/Modal.test.js @@ -8,6 +8,9 @@ const ModalTester = { return this.$refs.container }, }, + updated () { + console.log('updated') + }, render () { const modalProps = { @@ -32,6 +35,7 @@ const ModalTester = { describe('Modal', () => { it('render correctly', () => { const wrapper = mount(ModalTester) + wrapper.setProps({ visible: true }) expect(wrapper.html()).toMatchSnapshot() const wrapper1 = mount( { From 6cdc08102f714771c951d76d9003c23af0c48280 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 18 May 2018 14:30:17 +0800 Subject: [PATCH 3/3] test: update modal test --- components/modal/__tests__/Modal.test.js | 23 +++++++++++-------- .../__snapshots__/Modal.test.js.snap | 21 ++++++++++++++++- tests/setup.js | 4 ++-- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/components/modal/__tests__/Modal.test.js b/components/modal/__tests__/Modal.test.js index 67dae5b67..b0c180f22 100644 --- a/components/modal/__tests__/Modal.test.js +++ b/components/modal/__tests__/Modal.test.js @@ -1,4 +1,5 @@ import { mount } from '@vue/test-utils' +import Vue from 'vue' import Modal from '..' const ModalTester = { @@ -8,10 +9,6 @@ const ModalTester = { return this.$refs.container }, }, - updated () { - console.log('updated') - }, - render () { const modalProps = { props: { @@ -33,18 +30,24 @@ const ModalTester = { } describe('Modal', () => { - it('render correctly', () => { - const wrapper = mount(ModalTester) - wrapper.setProps({ visible: true }) - expect(wrapper.html()).toMatchSnapshot() - const wrapper1 = mount( + it('render correctly', (done) => { + const wrapper = mount( { render () { return }, } ) - expect(wrapper1.html()).toMatchSnapshot() + expect(wrapper.html()).toMatchSnapshot() + // https://github.com/vuejs/vue-test-utils/issues/624 + const wrapper1 = mount(ModalTester, { + sync: false, + }) + wrapper1.setProps({ visible: true }) + Vue.nextTick(() => { + expect(wrapper1.html()).toMatchSnapshot() + done() + }) }) it('render without footer', () => { diff --git a/components/modal/__tests__/__snapshots__/Modal.test.js.snap b/components/modal/__tests__/__snapshots__/Modal.test.js.snap index 891c81e17..b6d4b6eae 100644 --- a/components/modal/__tests__/__snapshots__/Modal.test.js.snap +++ b/components/modal/__tests__/__snapshots__/Modal.test.js.snap @@ -2,7 +2,26 @@ exports[`Modal render correctly 1`] = `
-
+
+
+
+ +
+
`; diff --git a/tests/setup.js b/tests/setup.js index def324f67..c6a2fab32 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -1,5 +1,5 @@ -import Vue from 'vue' -Vue.config.silent = true +// import Vue from 'vue' +// Vue.config.silent = true /* eslint-disable global-require */ if (typeof window !== 'undefined') {