mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-04-29 12:54:53 +08:00
Text tests
This commit is contained in:
@@ -6,6 +6,6 @@ export default {
|
|||||||
...StylePropTypes.TypographicPropTypes
|
...StylePropTypes.TypographicPropTypes
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TextDefaultStyles = {
|
export const TextDefaultStyle = {
|
||||||
display: 'inline'
|
display: 'inline'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class Text extends React.Component {
|
|||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
className: '',
|
className: '',
|
||||||
component: 'div'
|
component: 'span'
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
67
src/modules/Text/index.spec.js
Normal file
67
src/modules/Text/index.spec.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import assert from 'assert';
|
||||||
|
import React from 'react/addons';
|
||||||
|
|
||||||
|
import { TextDefaultStyle } from './TextStylePropTypes';
|
||||||
|
import Text from '.';
|
||||||
|
|
||||||
|
const ReactTestUtils = React.addons.TestUtils;
|
||||||
|
|
||||||
|
function shallowRender(component, context = {}) {
|
||||||
|
const shallowRenderer = React.addons.TestUtils.createRenderer();
|
||||||
|
shallowRenderer.render(component, context);
|
||||||
|
return shallowRenderer.getRenderOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
suite('Text', () => {
|
||||||
|
test('defaults', () => {
|
||||||
|
const result = ReactTestUtils.renderIntoDocument(<Text />);
|
||||||
|
const root = React.findDOMNode(result);
|
||||||
|
|
||||||
|
assert.equal((root.tagName).toLowerCase(), 'span');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prop "children"', () => {
|
||||||
|
const children = 'children';
|
||||||
|
const result = shallowRender(<Text>{children}</Text>);
|
||||||
|
|
||||||
|
assert.equal(result.props.children, children);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prop "className"', () => {
|
||||||
|
const className = 'className';
|
||||||
|
const result = shallowRender(<Text className={className} />);
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
(result.props.className).indexOf(className) > -1,
|
||||||
|
'"className" was not transferred'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prop "component"', () => {
|
||||||
|
const type = 'a';
|
||||||
|
const result = ReactTestUtils.renderIntoDocument(<Text component={type} />);
|
||||||
|
const root = React.findDOMNode(result);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
(root.tagName).toLowerCase(),
|
||||||
|
type,
|
||||||
|
'"component" did not produce the correct DOM node type'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prop "style"', () => {
|
||||||
|
const initial = shallowRender(<Text />);
|
||||||
|
assert.deepEqual(
|
||||||
|
initial.props.style,
|
||||||
|
TextDefaultStyle,
|
||||||
|
'default "style" is incorrect'
|
||||||
|
);
|
||||||
|
|
||||||
|
const unsupported = shallowRender(<Text style={{ unsupported: 'true' }} />);
|
||||||
|
assert.deepEqual(
|
||||||
|
unsupported.props.style.unsupported,
|
||||||
|
null,
|
||||||
|
'unsupported "style" properties must not be transferred'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user