-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plugin, and ElemenAssertion class
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |