Skip to content

Commit

Permalink
Add plugin, and ElemenAssertion class
Browse files Browse the repository at this point in the history
  • Loading branch information
suany0805 committed Nov 12, 2024
1 parent 512f251 commit 190ce45
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/native/src/lib/ElementAssertion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Assertion } from "@assertive-ts/core";
import { ReactTestInstance } from "react-test-renderer";

export class ElementAssertion extends Assertion<ReactTestInstance> {
public constructor(actual: ReactTestInstance) {
super(actual);
}

}
32 changes: 32 additions & 0 deletions packages/native/src/main.ts
Original file line number Diff line number Diff line change
@@ -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<ReactTestInstance, ElementAssertion> = {
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];

0 comments on commit 190ce45

Please sign in to comment.