Skip to content

Commit

Permalink
test: fix test to always query newly attached node
Browse files Browse the repository at this point in the history
Signed-off-by: Rong Sen Ng (motss) <wes.ngrongsen@gmail.com>
  • Loading branch information
motss committed Jan 5, 2024
1 parent 7ef9452 commit 703ae32
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/__tests__/date-picker/app-date-picker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,14 @@ describe(appDatePickerName, () => {
);

// START: Go to year grid view
const yearDropdown = el.query<Button>(elementSelectors.yearDropdown);
let yearDropdown = el.query<Button>(elementSelectors.yearDropdown);

yearDropdown?.focus();
yearDropdown?.click();

await elementUpdated(el);

const yearGrid = el.query<AppYearGrid>(elementSelectors.yearGrid);
let yearGrid = el.query<AppYearGrid>(elementSelectors.yearGrid);

expect(yearGrid).toBeInTheDocument();
// END: Go to year grid view
Expand Down Expand Up @@ -392,17 +392,18 @@ describe(appDatePickerName, () => {
expect(selectedYearMonth).toHaveTextContent(formatters.longMonthYearFormat(newSelectedDateDate));
// END: Select new month in calendar view to update current date

yearDropdown = el.query<Button>(elementSelectors.yearDropdown);

// START: Ensure old selected year remains unchanged
yearDropdown?.focus();
yearDropdown?.click();

await elementUpdated(el);

yearGrid = el.query<AppYearGrid>(elementSelectors.yearGrid);
selectedYear = yearGrid?.query<HTMLButtonElement>(elementSelectors.selectedYear);

// FIXME: `yearGrid` and `selectedYear` no longer exist in the document.
// expect(selectedYear).toBeInTheDocument();
expect(selectedYear).exist;

expect(selectedYear).toBeInTheDocument();
expect(selectedYear).toHaveAttribute('aria-label', new Date(testValue).getUTCFullYear().toString());
// END: Ensure old selected year remains unchanged
});
Expand Down

0 comments on commit 703ae32

Please sign in to comment.