From 524cfe7e01455e97e00aa036b8b8d803f92d91bb Mon Sep 17 00:00:00 2001
From: tangjinzhou <415800467@qq.com>
Date: Mon, 14 May 2018 09:49:26 +0800
Subject: [PATCH] test: update button test
---
.../__snapshots__/index.test.js.snap | 21 ++
components/button/__tests__/index.test.js | 229 +++++++++---------
components/index.js | 2 +-
package.json | 4 -
4 files changed, 142 insertions(+), 114 deletions(-)
create mode 100644 components/button/__tests__/__snapshots__/index.test.js.snap
diff --git a/components/button/__tests__/__snapshots__/index.test.js.snap b/components/button/__tests__/__snapshots__/index.test.js.snap
new file mode 100644
index 000000000..8714c1f5e
--- /dev/null
+++ b/components/button/__tests__/__snapshots__/index.test.js.snap
@@ -0,0 +1,21 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Button fixbug renders {0} , 0 and {false} 1`] = ``;
+
+exports[`Button fixbug renders {0} , 0 and {false} 2`] = ``;
+
+exports[`Button fixbug renders {0} , 0 and {false} 3`] = ``;
+
+exports[`Button renders Chinese characters correctly 1`] = `
+
+`;
+
+exports[`Button renders Chinese characters correctly 2`] = `
+
+`;
+
+exports[`Button renders correctly 1`] = ``;
+
+exports[`Button should support link button 1`] = ``;
diff --git a/components/button/__tests__/index.test.js b/components/button/__tests__/index.test.js
index b22ea98ab..5f6626cff 100644
--- a/components/button/__tests__/index.test.js
+++ b/components/button/__tests__/index.test.js
@@ -1,9 +1,19 @@
import Button from '../index'
import Icon from '../../icon'
import { mount } from '@vue/test-utils'
+import { renderToString } from '@vue/server-test-utils'
import Vue from 'vue'
describe('Button', () => {
+ it('renders correctly', () => {
+ const wrapper = renderToString({
+ render () {
+ return
+ },
+ })
+ expect(wrapper).toMatchSnapshot()
+ })
+
it('create primary button', () => {
const wrapper = mount({
render (h) {
@@ -12,124 +22,125 @@ describe('Button', () => {
})
expect(wrapper.contains('.ant-btn-primary')).toBe(true)
})
- // it('renders Chinese characters correctly', (done) => {
- // const wrapper = mount(
- // {
- // render (h) {
- // return
- // },
- // }
- // )
- // expect(wrapper.text()).to.equal('按 钮')
- // const wrapper1 = mount(
- // {
- // render (h) {
- // return
- // },
- // }
- // )
- // expect(wrapper1.text()).to.equal('按钮')
+ it('renders Chinese characters correctly', (done) => {
+ const wrapper = mount(
+ {
+ render (h) {
+ return
+ },
+ }
+ )
+ expect(wrapper.text()).toBe('按 钮')
- // const wrapper2 = mount(
- // {
- // render (h) {
- // return
- // },
- // }
- // )
- // expect(wrapper2.text()).to.equal('按钮')
+ const wrapper1 = renderToString(
+ {
+ render (h) {
+ return
+ },
+ }
+ )
+ expect(wrapper1).toMatchSnapshot()
- // const wrapper3 = mount(
- // {
- // render (h) {
- // return
- // },
- // }
- // )
- // Vue.nextTick(() => {
- // expect(wrapper3.find('.ant-btn')[0].hasClass('ant-btn-two-chinese-chars')).to.equal(true);
- // done()
- // })
- // })
- // it('should change loading state instantly by default', () => {
- // const DefaultButton = {
- // data(){
- // return {
- // loading: false,
- // }
- // },
- // methods: {
- // enterLoading () {
- // this.loading = true
- // }
- // },
+ const wrapper2 = renderToString(
+ {
+ render (h) {
+ return
+ },
+ }
+ )
+ expect(wrapper2).toMatchSnapshot()
- // render() {
- // return ;
- // }
- // }
- // const wrapper = mount(DefaultButton)
- // wrapper.trigger('click');
- // Vue.nextTick(() => {
- // expect(wrapper.find('.ant-btn-loading').length).to.equal(1);
- // })
- // });
+ const wrapper3 = mount(
+ {
+ render (h) {
+ return
+ },
+ }
+ )
+ Vue.nextTick(() => {
+ expect(wrapper3.find('.ant-btn').contains('.ant-btn-two-chinese-chars')).toBe(true)
+ done()
+ })
+ })
+ it('should change loading state instantly by default', () => {
+ const DefaultButton = {
+ data () {
+ return {
+ loading: false,
+ }
+ },
+ methods: {
+ enterLoading () {
+ this.loading = true
+ },
+ },
- // it('should change loading state with delay', () => {
- // const DefaultButton = {
- // data(){
- // return {
- // loading: false,
- // }
- // },
- // methods: {
- // enterLoading () {
- // this.loading = { delay: 1000 }
- // }
- // },
+ render () {
+ return
+ },
+ }
+ const wrapper = mount(DefaultButton)
+ wrapper.trigger('click')
+ Vue.nextTick(() => {
+ expect(wrapper.findAll('.ant-btn-loading').length).toBe(1)
+ })
+ })
- // render() {
- // return ;
- // }
- // }
- // const wrapper = mount(DefaultButton)
- // wrapper.trigger('click');
- // Vue.nextTick(() => {
- // expect(wrapper.hasClass('ant-btn-loading').length).to.equal(false);
- // })
- // });
+ it('should change loading state with delay', (done) => {
+ const DefaultButton = {
+ data () {
+ return {
+ loading: false,
+ }
+ },
+ methods: {
+ enterLoading () {
+ this.loading = { delay: 1000 }
+ },
+ },
- // it('should support link button', () => {
- // const wrapper = mount({
- // render (h) {
- // return
- // },
- // })
- // expect(wrapper.html()).to.matchSnapshot();
- // })
+ render () {
+ return
+ },
+ }
+ const wrapper = mount(DefaultButton)
+ wrapper.trigger('click')
+ Vue.nextTick(() => {
+ expect(wrapper.contains('.ant-btn-loading')).toBe(false)
+ done()
+ })
+ })
- // it('fixbug renders {0} , 0 and {false}', () => {
- // const wrapper = mount({
- // render (h) {
- // return
- // },
- // })
- // expect(wrapper.html()).to.matchSnapshot();
+ it('should support link button', () => {
+ const wrapper = mount({
+ render (h) {
+ return
+ },
+ })
+ expect(wrapper.html()).toMatchSnapshot()
+ })
- // const wrapper1 = mount({
- // render (h) {
- // return
- // },
- // })
- // expect(wrapper1.html()).to.matchSnapshot();
+ it('fixbug renders {0} , 0 and {false}', () => {
+ const wrapper = mount({
+ render (h) {
+ return
+ },
+ })
+ expect(wrapper.html()).toMatchSnapshot()
- // const wrapper2 = mount({
- // render (h) {
- // return
- // },
- // })
- // expect(wrapper2.html()).to.matchSnapshot();
+ const wrapper1 = mount({
+ render (h) {
+ return
+ },
+ })
+ expect(wrapper1.html()).toMatchSnapshot()
- // })
+ const wrapper2 = mount({
+ render (h) {
+ return
+ },
+ })
+ expect(wrapper2.html()).toMatchSnapshot()
+ })
})
diff --git a/components/index.js b/components/index.js
index 490891a42..7acf7ffd6 100644
--- a/components/index.js
+++ b/components/index.js
@@ -1,7 +1,7 @@
/* @remove-on-es-build-begin */
// this file is not used if use https://github.com/ant-design/babel-plugin-import
const ENV = process.env.NODE_ENV
-if (ENV !== 'production' &&
+if (ENV !== 'production' && ENV !== 'test' &&
typeof console !== 'undefined' &&
console.warn &&
typeof window !== 'undefined') {
diff --git a/package.json b/package.json
index ab46d8f22..18735d5e5 100644
--- a/package.json
+++ b/package.json
@@ -116,12 +116,10 @@
"merge2": "^1.2.1",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
- "mocha": "^3.5.3",
"mockdate": "^2.0.2",
"postcss": "^6.0.20",
"postcss-loader": "^2.1.2",
"pre-commit": "^1.2.2",
- "puppeteer": "^1.3.0",
"querystring": "^0.2.0",
"raw-loader": "^1.0.0-beta.0",
"reqwest": "^2.0.5",
@@ -129,8 +127,6 @@
"rucksack-css": "^1.0.2",
"selenium-server": "^3.0.1",
"semver": "^5.3.0",
- "sinon": "^4.0.2",
- "sinon-chai": "^2.8.0",
"style-loader": "^0.18.2",
"stylelint": "^8.1.1",
"stylelint-config-standard": "^17.0.0",