UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

79 lines (77 loc) 3.12 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() { return _super !== null && _super.apply(this, arguments) || this; } Child.prototype.render = function () { return (React.createElement("div", { id: 'child' }, this.context.foo)); }; return Child; }(React.Component)); Child.contextTypes = { foo: React.PropTypes.string.isRequired }; var Parent = (function (_super) { __extends(Parent, _super); function Parent() { return _super !== null && _super.apply(this, arguments) || this; } 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)))); }; return Parent; }(React.Component)); Parent.childContextTypes = { foo: React.PropTypes.string }; var App = (function (_super) { __extends(App, _super); function App() { return _super !== null && _super.apply(this, arguments) || this; } 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