diff --git a/packages/native/src/lib/ElementAssertion.ts b/packages/native/src/lib/ElementAssertion.ts new file mode 100644 index 0000000..b36cf69 --- /dev/null +++ b/packages/native/src/lib/ElementAssertion.ts @@ -0,0 +1,9 @@ +import { Assertion } from "@assertive-ts/core"; +import { ReactTestInstance } from "react-test-renderer"; + +export class ElementAssertion extends Assertion { + public constructor(actual: ReactTestInstance) { + super(actual); + } + +} diff --git a/packages/native/src/main.ts b/packages/native/src/main.ts index e69de29..a6fe8a1 100644 --- a/packages/native/src/main.ts +++ b/packages/native/src/main.ts @@ -0,0 +1,32 @@ +import { Plugin } from "@assertive-ts/core"; +import { ReactTestInstance } from "react-test-renderer"; + +import { ElementAssertion } from "./lib/ElementAssertion"; + +declare module "@assertive-ts/core" { + + export interface Expect { + // eslint-disable-next-line @typescript-eslint/prefer-function-type + (actual: ReactTestInstance): ElementAssertion; + } +} + +const ElementPlugin: Plugin = { + Assertion: ElementAssertion, + insertAt: "top", + predicate: (actual): actual is ReactTestInstance => + typeof actual === "object" + && actual !== null + && "instance" in actual + && typeof actual.instance === "object" + && "type" in actual + && typeof actual.type === "object" + && "props" in actual + && typeof actual.props === "object" + && "parent" in actual + && typeof actual.parent === "object" + && "children" in actual + && typeof actual.children === "object", +}; + +export const NativePlugin = [ElementPlugin];