Skip to content

Commit dcded59

Browse files
kdquistanchalalopenchi
authored andcommitted
refactor: Address CR comments
1 parent 311d4f0 commit dcded59

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

packages/native/test/lib/ElementAssertion.test.tsx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AssertionError, expect } from "@assertive-ts/core";
22
import { fireEvent, render } from "@testing-library/react-native";
3-
import { useState, useCallback } from "react";
3+
import { useState, useCallback, ReactElement } from "react";
44
import {
55
View,
66
TextInput,
@@ -11,29 +11,27 @@ import {
1111

1212
import { ElementAssertion } from "../../src/lib/ElementAssertion";
1313

14-
const SimpleToggleText: React.FC = () => {
14+
function SimpleToggleText(): ReactElement {
1515
const [isVisible, setIsVisible] = useState(true);
1616

1717
const handleToggle = useCallback((): void => {
18-
setIsVisible((prev: boolean) => !prev);
18+
setIsVisible(prev => !prev);
1919
}, []);
2020

2121
return (
2222
<View>
2323
<Text
24-
testID="textElement"
2524
style={{ display: isVisible ? "flex" : "none" }}
2625
>
2726
{"Toggle me!"}
2827
</Text>
2928
<Button
30-
testID="toggleButton"
3129
title="Toggle Text"
3230
onPress={handleToggle}
3331
/>
3432
</View>
3533
);
36-
};
34+
}
3735

3836
describe("[Unit] ElementAssertion.test.ts", () => {
3937
describe(".toBeDisabled", () => {
@@ -191,10 +189,10 @@ describe("[Unit] ElementAssertion.test.ts", () => {
191189
describe (".toBeVisible", () => {
192190
context("when the modal is visible", () => {
193191
it("returns the assertion instance", () => {
194-
const element = render(
192+
const { getByTestId } = render(
195193
<Modal testID="id" visible={true} />,
196194
);
197-
const test = new ElementAssertion(element.getByTestId("id"));
195+
const test = new ElementAssertion(getByTestId("id"));
198196

199197
expect(test.toBeVisible()).toBe(test);
200198
expect(() => test.not.toBeVisible())
@@ -206,14 +204,14 @@ describe("[Unit] ElementAssertion.test.ts", () => {
206204
context("when the element contains 'display' property", () => {
207205
context("and display = none", () => {
208206
it("throws an error", () => {
209-
const element = render(
207+
const { getByText, getByRole } = render(
210208
<SimpleToggleText />,
211209
);
212-
const textElement = new ElementAssertion(element.getByTestId("textElement"));
210+
const textElement = new ElementAssertion(getByText("Toggle me!"));
213211

214212
expect(textElement.toBeVisible()).toBeEqual(textElement);
215213

216-
const toggleButton = element.getByTestId("toggleButton");
214+
const toggleButton = getByRole("button", { name: "Toggle Text" });
217215
fireEvent.press(toggleButton);
218216

219217
expect(textElement.not.toBeVisible()).toBeEqual(textElement);
@@ -222,10 +220,10 @@ describe("[Unit] ElementAssertion.test.ts", () => {
222220

223221
context("and display = flex", () => {
224222
it("returns the assertion instance", () => {
225-
const element = render(
223+
const { getByTestId } = render(
226224
<View testID="id" style={{ display: "flex" }} />,
227225
);
228-
const test = new ElementAssertion(element.getByTestId("id"));
226+
const test = new ElementAssertion(getByTestId("id"));
229227

230228
expect(test.toBeVisible()).toBe(test);
231229
expect(() => test.not.toBeVisible())
@@ -237,10 +235,10 @@ describe("[Unit] ElementAssertion.test.ts", () => {
237235

238236
context("when the element contains 'accessibilityElementsHidden' property", () => {
239237
it("returns the assertion instance", () => {
240-
const element = render(
238+
const { getByTestId } = render(
241239
<View testID="id" accessibilityElementsHidden={false} />,
242240
);
243-
const test = new ElementAssertion(element.getByTestId("id"));
241+
const test = new ElementAssertion(getByTestId("id"));
244242

245243
expect(test.toBeVisible()).toBe(test);
246244
expect(() => test.not.toBeVisible())
@@ -251,10 +249,10 @@ describe("[Unit] ElementAssertion.test.ts", () => {
251249

252250
context("when the element contains 'importantForAccessibility' property", () => {
253251
it("returns the assertion instance", () => {
254-
const element = render(
252+
const { getByTestId } = render(
255253
<View testID="id" importantForAccessibility={"yes"} />,
256254
);
257-
const test = new ElementAssertion(element.getByTestId("id"));
255+
const test = new ElementAssertion(getByTestId("id"));
258256

259257
expect(test.toBeVisible()).toBe(test);
260258
expect(() => test.not.toBeVisible())
@@ -265,14 +263,14 @@ describe("[Unit] ElementAssertion.test.ts", () => {
265263

266264
context("when the parent element contains 'opacity' property", () => {
267265
context("and parent opacity = 0", () => {
268-
const element = render(
266+
const { getByTestId } = render(
269267
<View testID="parentId" style={{ opacity: 0 }} >
270268
<View testID="childId" style={{ opacity: 1 }} />
271269
</View>,
272270
);
273271

274-
const parent = new ElementAssertion(element.getByTestId("parentId"));
275-
const child = new ElementAssertion(element.getByTestId("childId"));
272+
const parent = new ElementAssertion(getByTestId("parentId"));
273+
const child = new ElementAssertion(getByTestId("childId"));
276274

277275
it("returns assertion instance for NOT visible elements", () => {
278276
expect(parent.not.toBeVisible()).toBeEqual(parent);
@@ -290,14 +288,14 @@ describe("[Unit] ElementAssertion.test.ts", () => {
290288
});
291289

292290
context("and child opacity = 0", () => {
293-
const element = render(
291+
const { getByTestId } = render(
294292
<View testID="parentId" style={{ opacity: 1 }} >
295293
<View testID="childId" style={{ opacity: 0 }} />
296294
</View>,
297295
);
298296

299-
const parent = new ElementAssertion(element.getByTestId("parentId"));
300-
const child = new ElementAssertion(element.getByTestId("childId"));
297+
const parent = new ElementAssertion(getByTestId("parentId"));
298+
const child = new ElementAssertion(getByTestId("childId"));
301299

302300
it("returns assertion instance for visible parent and NOT visible child", () => {
303301
expect(parent.toBeVisible()).toBeEqual(parent);

0 commit comments

Comments
 (0)