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] 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') {