View tests

This commit is contained in:
Nicolas Gallagher
2015-09-01 16:45:00 -07:00
parent 95d6b98e9d
commit 653cfd71ce
2 changed files with 77 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
var webpackConfig = require('./webpack-base.config.js');
// entry is determined by karma config 'files' array
webpackConfig.devtool = 'inline-source-map'
webpackConfig.entry = {};
module.exports = function (config) {

View File

@@ -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'
);
});
});