UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

81 lines (79 loc) 3.07 kB
"use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; /* tslint:disable:no-unused-variable */ var React = require('react'); var ReactDOM = require('react-dom'); /* tslint:enable:no-unused-variable */ var Layer_1 = require('./Layer'); var LayerHost_1 = require('./LayerHost'); var expect = chai.expect; describe('Layer', function () { it('can render in a targeted LayerHost and pass context through', function () { var Child = (function (_super) { __extends(Child, _super); function Child() { _super.apply(this, arguments); } Child.prototype.render = function () { return (React.createElement("div", {id: 'child'}, this.context.foo)); }; Child.contextTypes = { foo: React.PropTypes.string.isRequired }; return Child; }(React.Component)); var Parent = (function (_super) { __extends(Parent, _super); function Parent() { _super.apply(this, arguments); } Parent.prototype.getChildContext = function () { return { foo: 'foo' }; }; Parent.prototype.render = function () { return (React.createElement("div", {id: 'parent'}, React.createElement(Layer_1.Layer, {hostId: 'foo'}, React.createElement(Child, null) ) )); }; Parent.childContextTypes = { foo: React.PropTypes.string }; return Parent; }(React.Component)); var App = (function (_super) { __extends(App, _super); function App() { _super.apply(this, arguments); } App.prototype.render = function () { return (React.createElement("div", {id: 'app'}, React.createElement(Parent, null), React.createElement(LayerHost_1.LayerHost, {id: 'foo'}))); }; return App; }(React.Component)); var appElement = document.createElement('div'); try { document.body.appendChild(appElement); ReactDOM.render(React.createElement(App, null), appElement); var parentElement = appElement.querySelector('#parent'); expect(parentElement).is.not.empty; expect(parentElement.ownerDocument).is.not.empty; var childElement = appElement.querySelector('#child'); expect(childElement.textContent).equals('foo'); } finally { ReactDOM.unmountComponentAtNode(appElement); appElement.remove(); } }); }); //# sourceMappingURL=Layer.test.js.map