<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Share jest test for SelectV2 in Developer Q&amp;A Forum</title>
    <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258435#M1112</link>
    <description>&lt;P&gt;Thanks Nina, now it works.&lt;/P&gt;</description>
    <pubDate>Mon, 07 Oct 2024 15:04:01 GMT</pubDate>
    <dc:creator>DaveOps</dc:creator>
    <dc:date>2024-10-07T15:04:01Z</dc:date>
    <item>
      <title>Share jest test for SelectV2</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/257786#M1100</link>
      <description>&lt;P&gt;Can you share a example jest test for a SelectV2 component?&lt;/P&gt;&lt;P&gt;For some reason I am not able to make it work due to rendering of selectv2-menu options after a click event.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 08:56:54 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/257786#M1100</guid>
      <dc:creator>DaveOps</dc:creator>
      <dc:date>2024-10-02T08:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Share jest test for SelectV2</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258124#M1105</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/78577"&gt;@DaveOps&lt;/a&gt;, would you please share your failing tests and the errors why they fail? It would greatly help us figure out the issue.&lt;/P&gt;
&lt;P&gt;Best, Edu.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2024 09:07:45 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258124#M1105</guid>
      <dc:creator>educampver</dc:creator>
      <dc:date>2024-10-04T09:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: Share jest test for SelectV2</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258148#M1106</link>
      <description>&lt;P&gt;Sharing the code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;test("opens the dropdown with options showing", async () =&amp;gt; {
    render(
      &amp;lt;AppRoot&amp;gt;
        &amp;lt;GenericDropdown
          id="gd"
          icon={&amp;lt;span&amp;gt;Icon&amp;lt;/span&amp;gt;}
          options={options}
          value="30s"
          onChange={mockOnChange}
          ariaLabel="Select an option"
        /&amp;gt;
      &amp;lt;/AppRoot&amp;gt;,
      { baseElement: document.body } 
    );

    const user = userEvent.setup();
    const combobox = screen.getByRole('combobox');
    expect(combobox).toBeInTheDocument();

    await user.click(combobox);

    const listbox = await screen.findByRole('listbox');
    const option1 = await within(listbox).findByRole('option', { name: '5 seconds' });
    const option2 = await within(listbox).findByRole('option', { name: '15 seconds' });
    const option3 = await within(listbox).findByRole('option', { name: '30 seconds' });
    const option4 = await within(listbox).findByRole('option', { name: '1 minute' });
    const option5 = await within(listbox).findByRole('option', { name: '5 minutes' });

    expect(option1).toBeInTheDocument();
    expect(option2).toBeInTheDocument();
    expect(option3).toBeInTheDocument();
    expect(option4).toBeInTheDocument();
    expect(option5).toBeInTheDocument();
  });&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;After a click event on the input with role combobox, the options are not rendered and it can't find option1.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2024 13:12:22 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258148#M1106</guid>
      <dc:creator>DaveOps</dc:creator>
      <dc:date>2024-10-04T13:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: Share jest test for SelectV2</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258152#M1107</link>
      <description>&lt;P&gt;I see, using the combobox could be the issue, try using&amp;nbsp;&lt;CODE&gt;getByTestId('&lt;SPAN&gt;selectv2-trigger&lt;/SPAN&gt;')&lt;/CODE&gt;&amp;nbsp;instead.&lt;/P&gt;
&lt;P&gt;Cheers, Edu.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2024 13:38:21 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258152#M1107</guid>
      <dc:creator>educampver</dc:creator>
      <dc:date>2024-10-04T13:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Share jest test for SelectV2</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258155#M1108</link>
      <description>&lt;P&gt;I made the code change that you suggested which resulted into this error:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;FAIL  tests/components/GenericDropdown.test.tsx (7.413 s)
  GenericDropdown Component
    ✓ renders with the default value (47 ms)
    ✕ opens the dropdown with options showing (1088 ms)
    ○ skipped changes the value when a different option is selected

  ● GenericDropdown Component › opens the dropdown with options showing

    Unable to find role="option" and name "5 seconds"

    Ignored nodes: comments, script, style
    &amp;lt;div
      aria-multiselectable="false"
      class="Select_selectMenuListWrapperCSS__1x49mee9 strato-selectV2-menulist"
      id="react-select-3-listbox"
      role="listbox"
    &amp;gt;
      &amp;lt;div
        class="Select_selectVirtualizationWrapperCSS__1x49mee8"
        style="height: 160px; display: grid; grid-template-rows: 32px 32px 32px 32px 32px;"
      /&amp;gt;
    &amp;lt;/div&amp;gt;

      65 |     const listbox = await screen.findByRole('listbox');
      66 |
    &amp;gt; 67 |     const option1 = await within(listbox).findByRole('option', { name: '5 seconds' });
         |                                           ^
      68 |     const option2 = await within(listbox).findByRole('option', { name: '15 seconds' });
      69 |     const option3 = await within(listbox).findByRole('option', { name: '30 seconds' });
      70 |     const option4 = await within(listbox).findByRole('option', { name: '1 minute' });

      at waitForWrapper (../node_modules/@testing-library/dom/dist/wait-for.js:163:27)
      at ../node_modules/@testing-library/dom/dist/query-helpers.js:86:33
      at Object.&amp;lt;anonymous&amp;gt; (components/GenericDropdown.test.tsx:67:43)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 04 Oct 2024 14:05:44 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258155#M1108</guid>
      <dc:creator>DaveOps</dc:creator>
      <dc:date>2024-10-04T14:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: Share jest test for SelectV2</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258334#M1110</link>
      <description>&lt;DIV class=""&gt;Hi,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="" href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/78577" target="_blank" rel="noopener noreferrer"&gt;@DaveOps&lt;/A&gt;! A virtualization mock is needed for testing as the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;SelectV2&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;automatically virtualizes the options. Did you add &lt;FONT face="courier new,courier"&gt;setupVirtualizationMock()&lt;/FONT&gt; from the &lt;FONT face="courier new,courier"&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/64071"&gt;@dynatrace&lt;/a&gt;/strato-components-preview/testing&lt;/FONT&gt; package to the test?&lt;BR /&gt;Your tests could look something like this:&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;describe('&lt;SPAN class=""&gt;selectv2&lt;/SPAN&gt; testing', () =&amp;gt; { &lt;BR /&gt;  beforeEach(() =&amp;gt; { &lt;BR /&gt;    setupVirtualizationMock(); &lt;BR /&gt;  }); &lt;BR /&gt;  afterEach(()=&amp;gt; { &lt;BR /&gt;    clearVirtualizationMock(); &lt;BR /&gt;  }); &lt;BR /&gt;  test(...); &lt;BR /&gt;});&lt;/PRE&gt;&lt;DIV class=""&gt;Alternatively, you should also be able to call the &lt;FONT face="courier new,courier"&gt;setup()&lt;/FONT&gt; function to set up all the mocks necessary for testing the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;Strato components&lt;/SPAN&gt;.&lt;/DIV&gt;</description>
      <pubDate>Mon, 07 Oct 2024 08:16:55 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258334#M1110</guid>
      <dc:creator>nina</dc:creator>
      <dc:date>2024-10-07T08:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: Share jest test for SelectV2</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258435#M1112</link>
      <description>&lt;P&gt;Thanks Nina, now it works.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 15:04:01 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Share-jest-test-for-SelectV2/m-p/258435#M1112</guid>
      <dc:creator>DaveOps</dc:creator>
      <dc:date>2024-10-07T15:04:01Z</dc:date>
    </item>
  </channel>
</rss>

