Skip to content

Commit 496edc5

Browse files
CR: Move isEmpty to a helper file
1 parent debfd8a commit 496edc5

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

packages/native/src/lib/ToBeEmptyElementAssertion.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { Assertion, AssertionError } from "@assertive-ts/core";
22
import { 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+
*/
49
export 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
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ReactTestInstance } from "react-test-renderer";
2+
3+
export function isEmpty(element: ReactTestInstance): boolean {
4+
const children = element?.children;
5+
6+
if (!children) {
7+
return true;
8+
}
9+
10+
if (Array.isArray(children)) {
11+
return children.length === 0;
12+
}
13+
14+
return false;
15+
}

0 commit comments

Comments
 (0)