File tree Expand file tree Collapse file tree 2 files changed +23
-18
lines changed Expand file tree Collapse file tree 2 files changed +23
-18
lines changed Original file line number Diff line number Diff line change 11import { Assertion , AssertionError } from "@assertive-ts/core" ;
22import { ReactTestInstance } from "react-test-renderer" ;
33
4+ import { isEmpty } from "./helpers/helpers" ;
5+
6+ /**
7+ * Assertion for checking if a React element is empty.
8+ */
49export class ToBeEmptyElementAssertion extends Assertion < ReactTestInstance > {
510 public constructor ( actual : ReactTestInstance ) {
611 super ( actual ) ;
@@ -35,23 +40,9 @@ export class ToBeEmptyElementAssertion extends Assertion<ReactTestInstance> {
3540 } ) ;
3641
3742 return this . execute ( {
38- assertWhen : this . isEmpty ( this . actual ) ,
43+ assertWhen : isEmpty ( this . actual ) ,
3944 error,
4045 invertedError,
4146 } ) ;
4247 }
43-
44- private isEmpty ( element : ReactTestInstance ) : boolean {
45- const children = element ?. children ;
46-
47- if ( ! children ) {
48- return true ;
49- }
50-
51- if ( Array . isArray ( children ) ) {
52- return children . length === 0 ;
53- }
54-
55- return false ;
56- }
5748}
Original file line number Diff line number Diff line change @@ -7,9 +7,23 @@ import { ReactTestInstance } from "react-test-renderer";
77 * @returns A string representation of the instance.
88 */
99export function instanceToString ( instance : ReactTestInstance | null ) : string {
10- if ( instance === null ) {
11- return "null" ;
10+ if ( instance === null ) {
11+ return "null" ;
12+ }
13+
14+ return `<${ instance . type . toString ( ) } ... />` ;
15+ }
16+
17+ export function isEmpty ( element : ReactTestInstance ) : boolean {
18+ const children = element ?. children ;
19+
20+ if ( ! children ) {
21+ return true ;
22+ }
23+
24+ if ( Array . isArray ( children ) ) {
25+ return children . length === 0 ;
1226 }
1327
14- return `< ${ instance . type . toString ( ) } ... />` ;
28+ return false ;
1529}
You can’t perform that action at this time.
0 commit comments