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 __());
};
define(["require", "exports", "react", "react-addons-test-utils", "./BaseComponent"], function (require, exports, React, ReactTestUtils, BaseComponent_1) {
    "use strict";
    var assert = chai.assert, expect = chai.expect;
    var _originalOnError = BaseComponent_1.BaseComponent.onError;
    var TestComponent = (function (_super) {
        __extends(TestComponent, _super);
        function TestComponent() {
            return _super.apply(this, arguments) || this;
        }
        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 () {
        afterEach(function () {
            BaseComponent_1.BaseComponent.onError = _originalOnError;
        });
        _buildTestFor('componentWillMount');
        _buildTestFor('componentDidMount');
        _buildTestFor('shouldComponentUpdate');
        _buildTestFor('componentWillUpdate');
        _buildTestFor('componentWillReceiveProps');
        _buildTestFor('render');
        _buildTestFor('componentDidUpdate');
        _buildTestFor('componentWillUnmount');
        it('can resolve refs', function () {
            var Foo = (function (_super) {
                __extends(Foo, _super);
                function Foo() {
                    return _super.apply(this, arguments) || this;
                }
                Foo.prototype.render = function () {
                    return React.createElement("div", { ref: this._resolveRef('root') });
                };
                return Foo;
            }(BaseComponent_1.BaseComponent));
            var component = ReactTestUtils.renderIntoDocument(React.createElement(Foo, null));
            expect(component.root).to.exist;
        });
    });
    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
