UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

67 lines (65 loc) 2.36 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 __()); }; var BaseComponent_1 = require('./BaseComponent'); var assert = chai.assert; var TestComponent = (function (_super) { __extends(TestComponent, _super); function TestComponent() { _super.apply(this, arguments); } TestComponent.prototype.componentWillMount = function () { this._createNullRef(); }; TestComponent.prototype.componentDidMount = function () { this._createNullRef(); }; TestComponent.prototype.shouldComponentUpdate = function () { this._createNullRef(); }; TestComponent.prototype.componentWillUpdate = function () { this._createNullRef(); }; TestComponent.prototype.componentWillReceiveProps = function () { this._createNullRef(); }; TestComponent.prototype.render = function () { this._createNullRef(); return null; }; TestComponent.prototype.componentDidUpdate = function () { this._createNullRef(); }; TestComponent.prototype.componentWillUnmount = function () { this._createNullRef(); }; TestComponent.prototype._createNullRef = function () { var foo = null; // Calling a null foo(); }; return TestComponent; }(BaseComponent_1.BaseComponent)); describe('BaseComponent', function () { _buildTestFor('componentWillMount'); _buildTestFor('componentDidMount'); _buildTestFor('shouldComponentUpdate'); _buildTestFor('componentWillUpdate'); _buildTestFor('componentWillReceiveProps'); _buildTestFor('render'); _buildTestFor('componentDidUpdate'); _buildTestFor('componentWillUnmount'); }); function _buildTestFor(methodName) { it("calls the error logger on " + methodName + " exception", function () { var lastErrorMessage = null; BaseComponent_1.BaseComponent.onError = function (errorMessage, ex) { return lastErrorMessage = errorMessage; }; var c = new TestComponent(); c[methodName](); assert(lastErrorMessage !== null, 'Error callback not called'); }); } //# sourceMappingURL=BaseComponent.test.js.map