While testing frontend with yarn test facing error

  • What Grafana version and what operating system are you using?
    v9.3.6

  • What are you trying to achieve?
    Trying to test the grafana for frontend.

  • How are you trying to achieve it?

  • What happened?
    Facing test issues.

  • What did you expect to happen?

  • Can you copy/paste the configuration(s) that you are having problems with?
    Summary of all failing tests
    FAIL packages/grafana-data/src/datetime/formats.test.ts (6.094 s)
    ● Date Formats › localTimeFormat

    expect(received).toBe(expected) // Object.is equality

    Expected: “MM/DD/YYYY, hh:mm:ss A”
    Received: “MM/DD/YYYY, hh:mm:ss A”

    15 |     );
    16 |
    

    17 | expect(format).toBe(‘MM/DD/YYYY, hh:mm:ss A’);
    | ^
    18 | });
    19 | });
    20 |

    at Object.<anonymous> (packages/grafana-data/src/datetime/formats.test.ts:17:20)
    

    ● systemDateFormats › contains correct browser-localized date formats

    expect(received).toBe(expected) // Object.is equality

    Expected: “MM/DD/YYYY, hh:mm:ss A”
    Received: “MM/DD/YYYY, hh:mm:ss A”

    53 |   it('contains correct browser-localized date formats', () => {
    54 |     systemDateFormats.useBrowserLocale();
    

    55 | expect(systemDateFormats.fullDate).toBe(‘MM/DD/YYYY, hh:mm:ss A’);
    | ^
    56 | expect(systemDateFormats.fullDateMS).toBe(‘MM/DD/YYYY, hh:mm:ss.SSS A’);
    57 | expect(systemDateFormats.interval.millisecond).toBe(‘HH:mm:ss.SSS’);
    58 | expect(systemDateFormats.interval.second).toBe(‘HH:mm:ss’);

    at Object.<anonymous> (packages/grafana-data/src/datetime/formats.test.ts:55:40)
    

FAIL public/app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboard.test.tsx (20.236 s)
● SharePublic › renders default absolute time in input 2

TestingLibraryElementError: Unable to find an element with the text: 2022-08-30 00:00:00 to 2022-09-04 01:59:59. 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.

Ignored nodes: comments, <script />, <style />
<body>
  <div />
  <div
    data-overlay-container="true"
  >
    <div
      class="css-1dkh7gm"
    />
    <span
      data-focus-scope-start="true"
      hidden=""
    />
    <div
      class="css-hv4bd1"
      role="dialog"
      tabindex="-1"
    >
      <div
        class="css-1tc6q9g-modalHeader"
      >
        <h2
          class="css-y7vlju"
        >
          Share Panel
        </h2>
        <div
          class=""
        >
          <div
            class="css-af3vye"
            role="tablist"
          >
            <div
              class="css-1ciwanz"
            >
              <a
                aria-label="Tab Link"
                aria-selected="false"
                class="css-r385mj"
                href="#"
                role="tab"
              >
                Link
              </a>
            </div>
            <div
              class="css-1ciwanz"
            >
              <a
                aria-label="Tab Embed"
                aria-selected="false"
                class="css-r385mj"
                href="#"
                role="tab"
              >
                Embed
              </a>
            </div>
            <div
              class="css-1ciwanz"
            >
              <a
                aria-label="Tab Library panel"
                aria-selected="false"
                class="css-r385mj"
                href="#"
                role="tab"
              >
                Library panel
              </a>
            </div>
            <div
              class="css-1ciwanz"
            >
              <a
                aria-label="Tab Public dashboard"
                aria-selected="true"
                class="css-1xejmuh-activeTabStyle"
                href="#"
                role="tab"
              >
                Public dashboard
              </a>
            </div>
          </div>
        </div>
        <div
          class="css-1jjfrvq"
        >
          <button
            aria-label="Close dialogue"
            class="css-w7mcn5"
          >
            <div
              class="css-wf08df-Icon"
            />
          </button>
        </div>
      </div>
      <div
        class="css-1ad80n9"
      >
        <div
          class="css-w3hlsh"
        >
          <div
            class="css-ve64a7-horizontal-group"
            style="width: 100%; height: 100%;"
          >
            <div
              class="css-cvef6c-layoutChildrenWrapper"
            >
              <p
                class="css-1h9vdv"
              >
                Welcome to Grafana public dashboards alpha!
              </p>
            </div>
          </div>
          <div
            class="css-1haqjg7"
          >
            <p>
              To allow the current dashboard to be published publicly, toggle the switch. For now we do not support template variables or frontend datasources.
            </p>
            <p>
              We'd love your feedback. To share, please comment on this

              <a
                class="text-link"
                href="https://github.com/grafana/grafana/discussions/49253"
                rel="noreferrer"
                target="_blank"
              >
                GitHub discussion
              </a>
              .
            </p>
            <hr />
            <div
              class="css-zyj0hy"
            >
              <p>
                Before you click Save, please acknowledge the following information:
              </p>
              <fieldset
                class="css-1qipljx"
              >
                <div
                  class="css-1j7sh2x-vertical-group"
                  style="width: 100%; height: 100%;"
                >
                  <div
                    class="css-1df5zvj-layoutChildrenWrapper"
                  >
                    <div
                      class="css-ve64a7-horizontal-group"
                      style="width: 100%; height: 100%;"
                    >
                      <div
                        class="css-j4kjly-layoutChildrenWrapper"
                      >
                        <label
                          class="css-1sa3gk1"
                        >
                          <input
                            class="css-1quwxsq"
                            data-testid="data-testid public dashboard will be public checkbox"
                            type="checkbox"
                            value=""
                          />
                          <span
                            class="css-10xnr05"
                          />
                          <span
                            class="css-1pmpj74-Label"
                          >
                            Your entire dashboard will be public
                          </span>
                        </label>
                      </div>
                      <div
                        class="css-j4kjly-layoutChildrenWrapper"
                      >
                        <a
                          class="css-1kf0ycc-button"
                          href="https://grafana.com/docs/grafana/latest/dashboards/dashboard-public/"
                          rel="noopener noreferrer"
                          tabindex="0"
                          target="_blank"
                        >
                          <div
                            class="css-wf08df-Icon"
                          />
                        </a>
                      </div>
                    </div>
                  </div>
                  <div
                    class="css-1df5zvj-layoutChildrenWrapper"
                  >
                    <div
                      class="css-ve64a7-horizontal-group"
                      style="width: 100%; height: 100%;"
                    >
                      <div
                        class="css-j4kjly-layoutChildrenWrapper"
                      >
                        <label
                          class="css-1sa3gk1"
                        >
                          <input
                            class="css-1quwxsq"
                            data-testid="data-testid public dashboard limited datasources checkbox"
                            type="checkbox"
                            value=""
                          />
                          <span
                            class="css-10xnr05"
                          />
                          <span
                            class="css-1pmpj74-Label"
                          >
                            Publishing currently only works with a subset of datasources
                          </span>
                        </label>
                      </div>
                      <div
                        class="css-j4kjly-layoutChildrenWrapper"
                      >
                        <a
                          class="css-1kf0ycc-button"
                          href="https://grafana.com/docs/grafana/latest/datasources/"
                          rel="noopener noreferrer"
                          tabindex="0"
                          target="_blank"
                        >
                          <div
                            class="css-wf08df-Icon"
                          />
                        </a>
                      </div>
                    </div>
                  </div>
                  <div
                    class="css-1df5zvj-layoutChildrenWrapper"
                  >
                    <div
                      class="css-ve64a7-horizontal-group"
                      style="width: 100%; height: 100%;"
                    >
                      <div
                        class="css-j4kjly-layoutChildrenWrapper"
                      >
                        <label
                          class="css-1sa3gk1"
                        >
                          <input
                            class="css-1quwxsq"
                            data-testid="data-testid public dashboard cost may increase checkbox"
                            type="checkbox"
                            value=""
                          />
                          <span
                            class="css-10xnr05"
                          />
                          <span
                            class="css-1pmpj74-Label"
                          >
                            Making your dashboard public will cause queries to run each time the dashboard is viewed which may increase costs
                          </span>
                        </label>
                      </div>
                      <div
                        class="css-j4kjly-layoutChildrenWrapper"
                      >
                        <a
                          class="css-1kf0ycc-button"
                          href="https://grafana.com/docs/grafana/latest/enterprise/query-caching/"
                          rel="noopener noreferrer"
                          tabindex="0"
                          target="_blank"
                        >
                          <div
                            class="css-wf08df-Icon"
                          />
                        </a>
                      </div>
                    </div>
                  </div>
                </div>
              </fieldset>
            </div>
            <hr />
            <h4
              class="share-modal-info-text"
            >
              Public dashboard configuration
            </h4>
            <fieldset
              class="css-17mmrxm"
            >
              <div
                class="css-1j7sh2x-vertical-group"
                style="width: 100%; height: 100%;"
              >
                <div
                  class="css-1df5zvj-layoutChildrenWrapper"
                >
                  <div
                    class="css-3jfm24-vertical-group"
                    style="width: 100%; height: 100%;"
                  >
                    <div
                      class="css-1lta20o-layoutChildrenWrapper"
                    >
                      <div
                        class="css-jt4xma-Label"
                      >
                        <label>
                          <div
                            class="css-xhqy0o"
                          >
                            Time range
                          </div>
                          <span
                            class="css-zjkzrp-Label-description"
                          >
                            The public dashboard uses the default time settings of the dashboard
                          </span>
                        </label>
                      </div>
                    </div>
                    <div
                      class="css-1lta20o-layoutChildrenWrapper"
                    >
                      <div
                        class="css-pxgwmf"
                      >
                        <button
                          aria-label="data-testid TimePicker Open Button"
                          class="css-7b0jy3-input-input-input-wrapper"
                          type="button"
                        >
                          <span
                            class="css-15dl6a3"
                          >
                            <span>
                              2022-08-30 00:00:00 to 2022-09-04 00:59:59
                            </span>
                            <span
                              class="css-1n2bi9n"
                            />
                          </span>
                        </button>
                      </div>
                    </div>
                  </div>
                </div>
                <div
                  class="css-1df5zvj-layoutChildrenWrapper"
                >
                  <div
                    class="css-3jfm24-vertical-group"
                    style="width: 100%; height: 100%;"
                  >
                    <div
                      class="css-1lta20o-layoutChildrenWrapper"
                    >
                      <div
                        class="css-jt4xma-Label"
                      >
                        <label>
                          <div
                            class="css-xhqy0o"
                          >
                            Show annotations
                          </div>
                          <span
                            class="css-zjkzrp-Label-description"
                          >
                            Show annotations on public dashboard
                          </span>
                        </label>
                      </div>
                    </div>
                    <div
                      class="css-1lta20o-layoutChildrenWrapper"
                    >
                      <div
                        class="css-1so7yeh"
                      >
                        <input
                          data-testid="data-testid public dashboard on off switch for annotations"
                          id="switch-27"
                          type="checkbox"
                        />
                        <label
                          aria-label="Toggle switch"
                          for="switch-27"
                        />
                      </div>
                    </div>
                  </div>
                </div>
                <div
                  class="css-1df5zvj-layoutChildrenWrapper"
                >
                  <div
                    class="css-3jfm24-vertical-group"
                    style="width: 100%; height: 100%;"
                  >
                    <div
                      class="css-1lta20o-layoutChildrenWrapper"
                    >
                      <div
                        class="css-jt4xma-Label"
                      >
                        <label>
                          <div
                            class="css-xhqy0o"
                          >
                            Enabled
                          </div>
                          <span
                            class="css-zjkzrp-Label-description"
                          >
                            Configures whether current dashboard can be available publicly
                          </span>
                        </label>
                      </div>
                    </div>
                    <div
                      class="css-1lta20o-layoutChildrenWrapper"
                    >
                      <div
                        class="css-1so7yeh"
                      >
                        <input
                          data-testid="data-testid public dashboard on off switch"
                          id="switch-28"
                          type="checkbox"
                        />
                        <label
                          aria-label="Toggle switch"
                          for="switch-28"
                        />
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </fieldset>
            <div
              class="css-ve64a7-horizontal-group"
              style="width: 100%; height: 100%;"
            >
              <div
                class="css-cvef6c-layoutChildrenWrapper"
              >
                <div
                  class="css-1j7sh2x-vertical-group"
                  style="width: 100%; height: 100%;"
                >
                  <div
                    class="css-bxa289-layoutChildrenWrapper"
                  >
                    <button
                      class="css-1sara2j-button"
                      data-testid="data-testid public dashboard save config button"
                      disabled=""
                      type="button"
                    >
                      <span
                        class="css-1mhnkuh"
                      >
                        Create public dashboard
                      </span>
                    </button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <span
      data-focus-scope-end="true"
      hidden=""
    />
  </div>
</body>

  146 |
  147 |     await screen.findByText('Welcome to Grafana public dashboards alpha!');
> 148 |     expect(screen.getByText('2022-08-30 00:00:00 to 2022-09-04 01:59:59')).toBeInTheDocument();
      |                   ^
  149 |   });
  150 |   it('when modal is opened, then loader spinner appears and inputs are disabled', async () => {
  151 |     mockDashboard.meta.hasPublicDashboard = true;

  at Object.getElementError (.yarn/cache/@testing-library-dom-npm-8.13.0-de21374654-880f1872b9.zip/node_modules/@testing-library/dom/dist/config.js:38:19)
  at .yarn/cache/@testing-library-dom-npm-8.13.0-de21374654-880f1872b9.zip/node_modules/@testing-library/dom/dist/query-helpers.js:90:38
  at .yarn/cache/@testing-library-dom-npm-8.13.0-de21374654-880f1872b9.zip/node_modules/@testing-library/dom/dist/query-helpers.js:62:17
  at .yarn/cache/@testing-library-dom-npm-8.13.0-de21374654-880f1872b9.zip/node_modules/@testing-library/dom/dist/query-helpers.js:111:19
  at public/app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboard.test.tsx:148:19
  at fulfilled (.yarn/cache/tslib-npm-2.4.1-36f0ed04db-19480d6e03.zip/node_modules/tslib/tslib.js:115:62)

FAIL public/app/core/components/Select/FolderPicker.test.tsx (8.055 s)
● FolderPicker › should return the correct search results when typing in the select

expect(element).not.toBeInTheDocument()

expected document not to contain element, found <span>Dash Two</span> instead

  157 |
  158 |     expect(await screen.findByText('Dash Test')).toBeInTheDocument();
> 159 |     expect(screen.queryByText('Dash Two')).not.toBeInTheDocument();
      |                                                ^
  160 |   });
  161 | });
  162 |

  at public/app/core/components/Select/FolderPicker.test.tsx:159:48
  at fulfilled (.yarn/cache/tslib-npm-2.4.1-36f0ed04db-19480d6e03.zip/node_modules/tslib/tslib.js:115:62)

Test Suites: 3 failed, 2 skipped, 1036 passed, 1039 of 1041 total
Tests: 4 failed, 14 skipped, 8758 passed, 8776 total
Snapshots: 251 passed, 251 total
Time: 626.076 s
Ran all test suites.