From 653cfd71ce3f8033fd8bc9a5e6476bacf7885953 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 1 Sep 2015 16:45:00 -0700 Subject: [PATCH] View tests --- karma.config.js | 1 + src/modules/View/index.spec.js | 76 ++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/modules/View/index.spec.js diff --git a/karma.config.js b/karma.config.js index 6a4bf4ab..5f9378f8 100644 --- a/karma.config.js +++ b/karma.config.js @@ -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) { diff --git a/src/modules/View/index.spec.js b/src/modules/View/index.spec.js new file mode 100644 index 00000000..d58f4aa5 --- /dev/null +++ b/src/modules/View/index.spec.js @@ -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(); + const root = React.findDOMNode(result); + + assert.equal((root.tagName).toLowerCase(), 'div'); + }); + + test('prop "children"', () => { + const children = 'children'; + const result = shallowRender({children}); + + assert.equal(result.props.children, children); + }); + + test('prop "className"', () => { + const className = 'className'; + const result = shallowRender(); + + assert.ok( + (result.props.className).indexOf(className) > -1, + '"className" was not transferred' + ); + }); + + test('prop "component"', () => { + const type = 'a'; + const result = ReactTestUtils.renderIntoDocument(); + 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(); + + assert.equal( + result.props.style.pointerEvents, + 'box-only' + ); + }); + + test('prop "style"', () => { + const initial = shallowRender(); + assert.deepEqual( + initial.props.style, + ViewDefaultStyle, + 'default "style" is incorrect' + ); + + const unsupported = shallowRender(); + assert.deepEqual( + unsupported.props.style.unsupported, + null, + 'unsupported "style" properties must not be transferred' + ); + }); +});