Skip to content

Commit c61ba82

Browse files
committed
Add plugin, and ElemenAssertion class
1 parent 00482ca commit c61ba82

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

examples/mocha/test/hooks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* eslint-disable react-hooks/rules-of-hooks */
2-
import { usePlugin } from "@assertive-ts/core";
3-
import { SymbolPlugin } from "@examples/symbol-plugin";
2+
//import { usePlugin } from "@assertive-ts/core";
3+
//import { SymbolPlugin } from "@examples/symbol-plugin";
44
import { RootHookObject } from "mocha";
55

66
export function mochaHooks(): RootHookObject {
77
return {
88
beforeAll() {
9-
usePlugin(SymbolPlugin);
9+
//usePlugin(SymbolPlugin);
1010
},
1111
};
1212
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Assertion } from "@assertive-ts/core";
2+
import { ReactTestInstance } from "react-test-renderer";
3+
4+
export class ElementAssertion extends Assertion<ReactTestInstance> {
5+
public constructor(actual: ReactTestInstance) {
6+
super(actual);
7+
}
8+
9+
}

packages/native/src/main.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Plugin } from "@assertive-ts/core";
2+
import { ReactTestInstance } from "react-test-renderer";
3+
4+
import { ElementAssertion } from "./lib/ElementAssertion";
5+
6+
declare module "@assertive-ts/core" {
7+
8+
export interface Expect {
9+
// eslint-disable-next-line @typescript-eslint/prefer-function-type
10+
(actual: ReactTestInstance): ElementAssertion;
11+
}
12+
}
13+
14+
const ElementPlugin: Plugin<ReactTestInstance, ElementAssertion> = {
15+
Assertion: ElementAssertion,
16+
insertAt: "top",
17+
predicate: (actual): actual is ReactTestInstance =>
18+
typeof actual === "object"
19+
&& actual !== null
20+
&& "instance" in actual
21+
&& typeof actual.instance === "object"
22+
&& "type" in actual
23+
&& typeof actual.type === "object"
24+
&& "props" in actual
25+
&& typeof actual.props === "object"
26+
&& "parent" in actual
27+
&& typeof actual.parent === "object"
28+
&& "children" in actual
29+
&& typeof actual.children === "object",
30+
};
31+
32+
export const NativePlugin = [ElementPlugin];

0 commit comments

Comments
 (0)