提交 84647fa1 编写于 作者: P popomore

test: add simple testcase for popover

上级 52fbd050
......@@ -2,7 +2,9 @@
"extends": ["eslint-config-airbnb"],
"env": {
"browser": true,
"node": true
"node": true,
"mocha": true,
"jest": true
},
"ecmaFeatures": {
"jsx": true
......
......@@ -33,6 +33,7 @@ const Popover = React.createClass({
return (
<Tooltip transitionName={transitionName}
ref="tooltip"
{...this.props}
overlay={this.getOverlay()}>
{this.props.children}
......@@ -40,6 +41,10 @@ const Popover = React.createClass({
);
},
getPopupDomNode() {
return this.refs.tooltip.refs.trigger.popupDomNode;
},
getOverlay() {
return <div>
<div className={prefixCls + '-title'}>
......
......@@ -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",
......
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(
<Popover overlay="console.log('hello world')" title="code" trigger="click">
<a href="#">show me your code</a>
</Popover>
);
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(/<div class="ant-popover-title".*?>code<\/div>/);
expect(popup.innerHTML).to.match(/<div class="ant-popover-content".*?>console\.log\('hello world'\)<\/div>/);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册