From 84647fa12d3bf776421c622d8b2bf1548a66460a Mon Sep 17 00:00:00 2001 From: popomore Date: Wed, 4 Nov 2015 17:15:33 +0800 Subject: [PATCH] test: add simple testcase for popover --- .eslintrc | 4 +++- components/popover/index.jsx | 5 +++++ package.json | 3 ++- tests/popover.test.js | 29 +++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/popover.test.js diff --git a/.eslintrc b/.eslintrc index d3e4cbe29d..af503e70ad 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,7 +2,9 @@ "extends": ["eslint-config-airbnb"], "env": { "browser": true, - "node": true + "node": true, + "mocha": true, + "jest": true }, "ecmaFeatures": { "jsx": true diff --git a/components/popover/index.jsx b/components/popover/index.jsx index e401f4a856..24f685bde6 100644 --- a/components/popover/index.jsx +++ b/components/popover/index.jsx @@ -33,6 +33,7 @@ const Popover = React.createClass({ return ( {this.props.children} @@ -40,6 +41,10 @@ const Popover = React.createClass({ ); }, + getPopupDomNode() { + return this.refs.tooltip.refs.trigger.popupDomNode; + }, + getOverlay() { return
diff --git a/package.json b/package.json index 03154e6ab3..ab86db3d10 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "eslint-config-airbnb": "^0.1.0", "eslint-plugin-babel": "^2.1.1", "eslint-plugin-react": "^3.3.1", + "expect.js": "~0.3.1", "extract-text-webpack-plugin": "^0.8.1", "gh-pages": "^0.3.1", "jest-cli": "~0.6.1", @@ -105,7 +106,7 @@ "clean": "rm -rf _site dist", "deploy": "rm -rf node_modules && node scripts/install.js && npm run just-deploy", "just-deploy": "npm run clean && webpack --config webpack.deploy.config.js && NODE_ENV=PRODUCTION nico build && node scripts/deploy.js", - "lint": "eslint components index.js --ext '.js,.jsx'", + "lint": "eslint components test index.js --ext '.js,.jsx'", "test": "npm run lint && webpack && npm run jest", "jest": "jest", "pub": "sh ./scripts/publish.sh", diff --git a/tests/popover.test.js b/tests/popover.test.js new file mode 100644 index 0000000000..1fe285f5ab --- /dev/null +++ b/tests/popover.test.js @@ -0,0 +1,29 @@ +import React from 'react'; +import expect from 'expect.js'; +import TestUtils from 'react-addons-test-utils'; + +jest.dontMock('../components/popover/index'); + +const Popover = require('../components/popover/index'); + +describe('Popover', function() { + it.only('should show overlay when trigger is clicked', () => { + const popover = TestUtils.renderIntoDocument( + + show me your code + + ); + + expect(popover.getPopupDomNode()).to.be(undefined); + + TestUtils.Simulate.click( + TestUtils.findRenderedDOMComponentWithTag(popover, 'a') + ); + + const popup = popover.getPopupDomNode(); + expect(popup).not.to.be(undefined); + expect(popup.className).to.contain('ant-popover-placement-top'); + expect(popup.innerHTML).to.match(/
code<\/div>/); + expect(popup.innerHTML).to.match(/
console\.log\('hello world'\)<\/div>/); + }); +}); -- GitLab