From 92df002fb08e79b135c12842cde5598e89b226f2 Mon Sep 17 00:00:00 2001 From: Meck Date: Mon, 14 Nov 2016 18:31:08 +0800 Subject: [PATCH] Introduce jest snapshots --- package.json | 4 +++- tests/__snapshots__/button.test.js.snap | 19 +++++++++++++++++ tests/button.test.js | 27 ++++++++----------------- 3 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 tests/__snapshots__/button.test.js.snap diff --git a/package.json b/package.json index 0ebfbf9ed3..fe82707c59 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "dora-plugin-upload": "^0.3.1", "enquire.js": "^2.1.1", "enzyme": "^2.6.0", + "enzyme-to-json": "^1.3.0", "es6-shim": "^0.35.0", "eslint": "^3.0.1", "eslint-config-airbnb": "latest", @@ -102,6 +103,7 @@ "eslint-plugin-react": "^6.1.2", "eslint-tinker": "^0.4.0", "history": "^4.4.0", + "jest": "^17.0.1", "jest-cli": "^17.0.0", "jsonml-to-react-component": "~0.2.0", "jsonml.js": "^0.1.0", @@ -111,9 +113,9 @@ "moment-timezone": "^0.5.5", "pre-commit": "1.x", "querystring": "^0.2.0", + "rc-queue-anim": "~0.12.4", "rc-scroll-anim": "~0.5.0", "rc-tween-one": "~0.11.0", - "rc-queue-anim": "~0.12.4", "react": "^15.0.0", "react-addons-test-utils": "^15.0.0", "react-copy-to-clipboard": "^4.0.1", diff --git a/tests/__snapshots__/button.test.js.snap b/tests/__snapshots__/button.test.js.snap new file mode 100644 index 0000000000..e9c1b2ac20 --- /dev/null +++ b/tests/__snapshots__/button.test.js.snap @@ -0,0 +1,19 @@ +exports[`Button renders Chinese characters correctly 1`] = ` + +`; + +exports[`Button renders correctly 1`] = ` + +`; diff --git a/tests/button.test.js b/tests/button.test.js index 5f6cc2a3ec..6ad29d39a5 100644 --- a/tests/button.test.js +++ b/tests/button.test.js @@ -1,31 +1,20 @@ import React from 'react'; -import TestUtils from 'react-addons-test-utils'; +import { render } from 'enzyme'; +import { renderToJson } from 'enzyme-to-json'; import Button from '../components/button/button'; describe('Button', function() { - let button; - let buttonNode; - - beforeEach(() => { - button = TestUtils.renderIntoDocument( + it('renders correctly', () => { + const wrapper = render( ); - buttonNode = TestUtils.findRenderedDOMComponentWithTag(button, 'button'); - }); - - it('should set the type to button by default', () => { - expect(buttonNode.type).toBe('button'); - }); - - it('should set the default className to button', () => { - expect(buttonNode.className).toBe('ant-btn'); + expect(renderToJson(wrapper)).toMatchSnapshot(); }); - it('should has a whitespace in two Chinese characters', () => { - button = TestUtils.renderIntoDocument( + it('renders Chinese characters correctly', () => { + const wrapper = render( ); - buttonNode = TestUtils.findRenderedDOMComponentWithTag(button, 'button'); - expect(buttonNode.textContent).toBe('按 钮'); + expect(renderToJson(wrapper)).toMatchSnapshot(); }); });