42 lines
2.8 KiB
JavaScript
42 lines
2.8 KiB
JavaScript
|
define(["require", "exports", "tslib", "react", "react-test-renderer", "./composeComponentAs"], function (require, exports, tslib_1, React, renderer, composeComponentAs_1) {
|
||
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
var Base = function (props) {
|
||
|
return React.createElement("div", { "data-value": props.value });
|
||
|
};
|
||
|
var DecoratorA = function (props) {
|
||
|
var DefaultRender = props.defaultRender, exampleProps = tslib_1.__rest(props, ["defaultRender"]);
|
||
|
return React.createElement("div", { "data-a": "a" }, DefaultRender ? React.createElement(DefaultRender, tslib_1.__assign({}, exampleProps)) : null);
|
||
|
};
|
||
|
var DecoratorB = function (props) {
|
||
|
var DefaultRender = props.defaultRender, exampleProps = tslib_1.__rest(props, ["defaultRender"]);
|
||
|
return React.createElement("div", { "data-b": "b" }, DefaultRender ? React.createElement(DefaultRender, tslib_1.__assign({}, exampleProps)) : null);
|
||
|
};
|
||
|
describe('composeComponentAs', function () {
|
||
|
it('passes Base to DecoratorA', function () {
|
||
|
var DecoratorAWithBase = (0, composeComponentAs_1.composeComponentAs)(DecoratorA, Base);
|
||
|
var component = renderer.create(React.createElement(DecoratorAWithBase, { value: "test" }));
|
||
|
expect(component.toJSON()).toMatchSnapshot();
|
||
|
});
|
||
|
it('passes Base to DecoratorB through DecoratorA', function () {
|
||
|
var DecoratorAAndBWithBase = (0, composeComponentAs_1.composeComponentAs)(DecoratorA, (0, composeComponentAs_1.composeComponentAs)(DecoratorB, Base));
|
||
|
var component = renderer.create(React.createElement(DecoratorAAndBWithBase, { value: "test" }));
|
||
|
expect(component.toJSON()).toMatchSnapshot();
|
||
|
});
|
||
|
it('passes Base as defaultRender to DecoratorB through DecoratorA', function () {
|
||
|
var DecoratorAAroundB = (0, composeComponentAs_1.composeComponentAs)(DecoratorA, DecoratorB);
|
||
|
var component = renderer.create(React.createElement(DecoratorAAroundB, { value: "test", defaultRender: Base }));
|
||
|
expect(component.toJSON()).toMatchSnapshot();
|
||
|
});
|
||
|
it('renders without defaultRender', function () {
|
||
|
var DecoratorAAroundB = (0, composeComponentAs_1.composeComponentAs)(DecoratorA, DecoratorB);
|
||
|
var component = renderer.create(React.createElement(DecoratorAAroundB, { value: "test" }));
|
||
|
expect(component.toJSON()).toMatchSnapshot();
|
||
|
});
|
||
|
it('avoids recomposing already-composed components', function () {
|
||
|
var DecoratorAAroundB = (0, composeComponentAs_1.composeComponentAs)(DecoratorA, DecoratorB);
|
||
|
expect((0, composeComponentAs_1.composeComponentAs)(DecoratorA, DecoratorB)).toBe(DecoratorAAroundB);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
//# sourceMappingURL=composeComponentAs.test.js.map
|