Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileAnnotationList test asserts nothing and would fail if it did assert #369

Open
pgarrison opened this issue Dec 18, 2024 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@pgarrison
Copy link
Contributor

1. The test asserts nothing

The following test does not actually assert anything: <FileAnnotationList /> file path representation has both canonical file path and file path adjusted to OS & allen mount point.

Demonstration

Apply the following patch to search for some nonsense text in the rendered output. The test still passes, though it should fail.

diff --git a/packages/core/components/FileDetails/test/FileAnnotationList.test.tsx b/packages/core/components/FileDetails/test/FileAnnotationList.test.tsx
index dbf1c8a0..80829dee 100644
--- a/packages/core/components/FileDetails/test/FileAnnotationList.test.tsx
+++ b/packages/core/components/FileDetails/test/FileAnnotationList.test.tsx
@@ -55,6 +55,7 @@ describe("<FileAnnotationList />", () => {
 
             // Assert
             [
+                "philip's nonsense",
                 "File Path (Canonical)",
                 canonicalFilePath,
                 "File Path (Local)",

Root cause

In the following snippet, where an assertion is supposed to happen, instead 4 promises are created, but their resolution is never checked.

            [
                "File Path (Canonical)",
                canonicalFilePath,
                "File Path (Local)",
                expectedLocalPath,
            ].forEach(async (cellText) => {
                expect(await findByText(cellText)).to.not.be.undefined;
            });

2. The test would fail if it did assert

The test could properly assert if written as follows. With this rewrite, the await findByText is not captured by the anonymous function async (cellText) => { and instead blocks test execution until it succeeds.

            for (const cellText of [
                "File Path (Canonical)",
                canonicalFilePath,
                "File Path (Local)",
                expectedLocalPath,
            ]) {
                expect(await findByText(cellText)).to.not.be.undefined;
            };

Running this modified test produces this error: Unable to find an element with the text: File Path (Canonical). This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

@pgarrison pgarrison added the bug Something isn't working label Dec 18, 2024
@pgarrison pgarrison self-assigned this Dec 18, 2024
@pgarrison
Copy link
Contributor Author

I plan to remove and replace this test as part of #368

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant