Uploaded image for project: 'OpenShift Dev Console'
  1. OpenShift Dev Console
  2. ODC-6265

Add react-testing-library jest-dom extension (with TypeScript support)

    XMLWordPrintable

Details

    • Story
    • Resolution: Unresolved
    • Normal
    • openshift-4.13
    • None
    • UI
    • 1
    • False
    • False
    • 0
    • undefined
    • Not Supported
    • ODC Sprint 217, ODC Sprint 218, ODC Sprint 227, ODC Sprint 228, ODC Sprint 229, ODC Sprint 230

    Description

      Description of problem:

      With ODC-5851 we introduced react-testing-library (or the "testing-library") to our code.

      Most react examples also uses the "jest-dom" extensions (https://testing-library.com/docs/ecosystem-jest-dom/) which provides additional semantic assertions like

      expect(...).toBeEnabled()
      expect(...).toBeDisabled()
      expect(...).toHaveValue(...)
      expect(...).toHaveDescription(...)
      expect(...).toBeChecked()
      

      This makes our tese case easier to understand then... for example:

      expect(element.getAttribute("disabled")).toEquals("disabled")
      expect((element as HTMLInputElement).value)).toEquals(...)
      

      To simplify our tests and make adopting the examples from the official website easier, we should also add the "jest-dom" extension.

      :warning: The problem with just adding the library is that the typescript definition breaks jest autocompletion / type definition. For example:

      expect("").to<tab> // doesn't show toEquals or toBeEnabled after installing the library!
      

      Actual results:

      1. react-testing-library jest-dom extension is not available

      Expected results:

      1. react-testing-library jest-dom should be available and tested with some of our react-testing-library tests (or a new one)
      2. Autocompletion / Type definition of expect() should still work !!

      Additional notes

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              cjerolim Christoph Jerolimov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: