mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-31 17:53:50 +00:00
View tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
var webpackConfig = require('./webpack-base.config.js');
|
var webpackConfig = require('./webpack-base.config.js');
|
||||||
// entry is determined by karma config 'files' array
|
// entry is determined by karma config 'files' array
|
||||||
|
webpackConfig.devtool = 'inline-source-map'
|
||||||
webpackConfig.entry = {};
|
webpackConfig.entry = {};
|
||||||
|
|
||||||
module.exports = function (config) {
|
module.exports = function (config) {
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import assert from 'assert';
|
||||||
|
import React from 'react/addons';
|
||||||
|
|
||||||
|
import { ViewDefaultStyle } from './ViewStylePropTypes';
|
||||||
|
import View from '.';
|
||||||
|
|
||||||
|
const ReactTestUtils = React.addons.TestUtils;
|
||||||
|
|
||||||
|
function shallowRender(component, context = {}) {
|
||||||
|
const shallowRenderer = React.addons.TestUtils.createRenderer();
|
||||||
|
shallowRenderer.render(component, context);
|
||||||
|
return shallowRenderer.getRenderOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
suite('View', () => {
|
||||||
|
test('defaults', () => {
|
||||||
|
const result = ReactTestUtils.renderIntoDocument(<View />);
|
||||||
|
const root = React.findDOMNode(result);
|
||||||
|
|
||||||
|
assert.equal((root.tagName).toLowerCase(), 'div');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prop "children"', () => {
|
||||||
|
const children = 'children';
|
||||||
|
const result = shallowRender(<View>{children}</View>);
|
||||||
|
|
||||||
|
assert.equal(result.props.children, children);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prop "className"', () => {
|
||||||
|
const className = 'className';
|
||||||
|
const result = shallowRender(<View className={className} />);
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
(result.props.className).indexOf(className) > -1,
|
||||||
|
'"className" was not transferred'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prop "component"', () => {
|
||||||
|
const type = 'a';
|
||||||
|
const result = ReactTestUtils.renderIntoDocument(<View component={type} />);
|
||||||
|
const root = React.findDOMNode(result);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
(root.tagName).toLowerCase(),
|
||||||
|
type,
|
||||||
|
'"component" did not produce the correct DOM node type'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prop "pointerEvents"', () => {
|
||||||
|
const result = shallowRender(<View pointerEvents="box-only" />);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
result.props.style.pointerEvents,
|
||||||
|
'box-only'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prop "style"', () => {
|
||||||
|
const initial = shallowRender(<View />);
|
||||||
|
assert.deepEqual(
|
||||||
|
initial.props.style,
|
||||||
|
ViewDefaultStyle,
|
||||||
|
'default "style" is incorrect'
|
||||||
|
);
|
||||||
|
|
||||||
|
const unsupported = shallowRender(<View style={{ unsupported: 'true' }} />);
|
||||||
|
assert.deepEqual(
|
||||||
|
unsupported.props.style.unsupported,
|
||||||
|
null,
|
||||||
|
'unsupported "style" properties must not be transferred'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user