summaryrefslogtreecommitdiff
path: root/preact/test/ts/hoc-test.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'preact/test/ts/hoc-test.tsx')
-rw-r--r--preact/test/ts/hoc-test.tsx50
1 files changed, 50 insertions, 0 deletions
diff --git a/preact/test/ts/hoc-test.tsx b/preact/test/ts/hoc-test.tsx
new file mode 100644
index 0000000..455d9e0
--- /dev/null
+++ b/preact/test/ts/hoc-test.tsx
@@ -0,0 +1,50 @@
+import { expect } from 'chai';
+import {
+ createElement,
+ ComponentFactory,
+ ComponentConstructor,
+ Component
+} from '../../';
+import { SimpleComponent, SimpleComponentProps } from './Component-test';
+
+export interface highlightedProps {
+ isHighlighted: boolean;
+}
+
+export function highlighted<T>(
+ Wrappable: ComponentFactory<T>
+): ComponentConstructor<T & highlightedProps> {
+ return class extends Component<T & highlightedProps> {
+ constructor(props: T & highlightedProps) {
+ super(props);
+ }
+
+ render() {
+ let className = this.props.isHighlighted ? 'highlighted' : '';
+ return (
+ <div className={className}>
+ <Wrappable {...this.props} />
+ </div>
+ );
+ }
+
+ toString() {
+ return `Highlighted ${Wrappable.name}`;
+ }
+ };
+}
+
+const HighlightedSimpleComponent = highlighted<SimpleComponentProps>(
+ SimpleComponent
+);
+
+describe('hoc', () => {
+ it('wraps the given component', () => {
+ const highlight = new HighlightedSimpleComponent({
+ initialName: 'initial name',
+ isHighlighted: true
+ });
+
+ expect(highlight.toString()).to.eq('Highlighted SimpleComponent');
+ });
+});