Skip to content

Commit 2aecd49

Browse files
kdquistanchalalopenchi
authored andcommitted
Update: CR comments
1 parent acfb187 commit 2aecd49

File tree

3 files changed

+30
-34
lines changed

3 files changed

+30
-34
lines changed

packages/native/src/lib/ToBeEmptyElementAssertion.ts renamed to packages/native/src/lib/ToBeEmptyAssertion.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
11
import { Assertion, AssertionError } from "@assertive-ts/core";
22
import { ReactTestInstance } from "react-test-renderer";
33

4-
import { isEmpty } from "./helpers/helpers";
4+
import { instanceToString, isEmpty } from "./helpers/helpers";
55

66
/**
77
* Assertion for checking if a React element is empty.
88
*/
9-
export class ToBeEmptyElementAssertion extends Assertion<ReactTestInstance> {
9+
export class ToBeEmptyAssertion extends Assertion<ReactTestInstance> {
1010
public constructor(actual: ReactTestInstance) {
1111
super(actual);
1212
}
1313

1414
public override toString = (): string => {
15-
if (this.actual === null) {
16-
return "null";
17-
}
18-
19-
return `<${this.actual.type.toString()} ... />`;
15+
return instanceToString(this.actual);
2016
};
2117

2218
/**
2319
* Check if the element is empty.
2420
*
2521
* @example
2622
* ```
27-
* expect(element).toBeEmptyElement();
23+
* expect(element).toBeEmpty();
2824
* ```
2925
*
3026
* @returns the assertion instance
3127
*/
32-
public toBeEmptyElement(): this {
28+
public toBeEmpty(): this {
3329
const error = new AssertionError({
3430
actual: this.actual,
3531
message: `Expected element ${this.toString()} to be empty.`,
3632
});
3733
const invertedError = new AssertionError({
3834
actual: this.actual,
39-
message: `Expected element ${this.toString()} to NOT be empty.`,
35+
message: `Expected element ${this.toString()} NOT to be empty.`,
4036
});
4137

4238
return this.execute({
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
import { ReactTestInstance } from "react-test-renderer";
22

3-
/**
4-
* Converts a ReactTestInstance to a string representation.
5-
*
6-
* @param instance The ReactTestInstance to convert.
7-
* @returns A string representation of the instance.
8-
*/
9-
export function instanceToString(instance: ReactTestInstance | null): string {
10-
if (instance === null) {
11-
return "null";
12-
}
13-
14-
return `<${instance.type.toString()} ... />`;
15-
}
16-
173
/**
184
* Checks if a value is empty.
195
*
@@ -31,3 +17,17 @@ export function isEmpty(value: unknown): boolean {
3117

3218
return false;
3319
}
20+
21+
/**
22+
* Converts a ReactTestInstance to a string representation.
23+
*
24+
* @param instance - The ReactTestInstance to convert.
25+
* @returns A string representation of the instance.
26+
*/
27+
export function instanceToString(instance: ReactTestInstance | null): string {
28+
if (instance === null) {
29+
return "null";
30+
}
31+
32+
return `<${instance.type.toString()} ... />`;
33+
}

packages/native/test/lib/ToBeEmptyElementAssertion.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import { AssertionError, expect } from "@assertive-ts/core";
22
import { render } from "@testing-library/react-native";
33
import { View, Text } from "react-native";
44

5-
import { ToBeEmptyElementAssertion } from "../../src/lib/ToBeEmptyElementAssertion";
5+
import { ToBeEmptyAssertion } from "../../src/lib/ToBeEmptyAssertion";
66

7-
describe("[Unit] ToBeEmptyElementAssertion.test.ts", () => {
8-
describe(".toBeEmptyElement", () => {
7+
describe("[Unit] toBeEmptyAssertion.test.ts", () => {
8+
describe(".toBeEmpty", () => {
99
context("when the element is empty", () => {
1010
it("returns the assertion instance", () => {
1111
const element = render(<View testID="id" />);
12-
const test = new ToBeEmptyElementAssertion(element.getByTestId("id"));
12+
const test = new ToBeEmptyAssertion(element.getByTestId("id"));
1313

14-
expect(test.toBeEmptyElement()).toBe(test);
15-
expect(() => test.not.toBeEmptyElement())
14+
expect(test.toBeEmpty()).toBe(test);
15+
expect(() => test.not.toBeEmpty())
1616
.toThrowError(AssertionError)
17-
.toHaveMessage("Expected element <View ... /> to NOT be empty.");
17+
.toHaveMessage("Expected element <View ... /> NOT to be empty.");
1818
});
1919
});
2020

@@ -25,10 +25,10 @@ describe("[Unit] ToBeEmptyElementAssertion.test.ts", () => {
2525
<Text>{"Not empty"}</Text>
2626
</View>,
2727
);
28-
const test = new ToBeEmptyElementAssertion(element.getByTestId("id"));
28+
const test = new ToBeEmptyAssertion(element.getByTestId("id"));
2929

30-
expect(test.not.toBeEmptyElement()).toBeEqual(test);
31-
expect(() => test.toBeEmptyElement())
30+
expect(test.not.toBeEmpty()).toBeEqual(test);
31+
expect(() => test.toBeEmpty())
3232
.toThrowError(AssertionError)
3333
.toHaveMessage("Expected element <View ... /> to be empty.");
3434
});

0 commit comments

Comments
 (0)