From 694b6de40d20d97d0a472d6210bf06d39fd9b3bc Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Fri, 24 Mar 2023 13:39:10 +0100 Subject: [PATCH] Avoid unnecessary destructuring --- src/Calendar/Navigation.spec.jsx | 29 ++++++++++++++++++++++++----- src/CenturyView.spec.jsx | 12 +++++++----- src/DecadeView.spec.jsx | 8 ++++++-- src/MonthView.spec.jsx | 8 ++++++-- src/MonthView/WeekNumbers.spec.jsx | 8 ++++---- src/MonthView/Weekdays.spec.jsx | 10 ++++------ src/YearView.spec.jsx | 8 ++++++-- 7 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/Calendar/Navigation.spec.jsx b/src/Calendar/Navigation.spec.jsx index 90c4d3c9..7198317d 100644 --- a/src/Calendar/Navigation.spec.jsx +++ b/src/Calendar/Navigation.spec.jsx @@ -23,7 +23,11 @@ describe('Navigation', () => { const children = [...container.firstElementChild.children]; - const [prev2, prev, drillUp, next, next2] = children; + const prev2 = children[0]; + const prev = children[1]; + const drillUp = children[2]; + const next = children[3]; + const next2 = children[4]; expect(children).toHaveLength(5); expect(prev2).toHaveAttribute('type', 'button'); @@ -38,7 +42,9 @@ describe('Navigation', () => { const children = [...container.firstElementChild.children]; - const [prev, drillUp, next] = children; + const prev = children[0]; + const drillUp = children[1]; + const next = children[2]; expect(children).toHaveLength(3); expect(prev).toHaveAttribute('type', 'button'); @@ -98,7 +104,12 @@ describe('Navigation', () => { />, ); - const [prev2, prev, , next, next2] = [...container.firstElementChild.children]; + const children = [...container.firstElementChild.children]; + + const prev2 = children[0]; + const prev = children[1]; + const next = children[3]; + const next2 = children[4]; expect(prev2).toHaveTextContent('prev2Label'); expect(prev).toHaveTextContent('prevLabel'); @@ -111,7 +122,9 @@ describe('Navigation', () => { , ); - const [, , navigation] = [...container.firstElementChild.children]; + const children = [...container.firstElementChild.children]; + + const navigation = children[2]; expect(navigation).toHaveAttribute('aria-live', 'polite'); }); @@ -129,7 +142,13 @@ describe('Navigation', () => { />, ); - const [prev2, prev, navigation, next, next2] = [...container.firstElementChild.children]; + const children = [...container.firstElementChild.children]; + + const prev2 = children[0]; + const prev = children[1]; + const navigation = children[2]; + const next = children[3]; + const next2 = children[4]; expect(prev2).toHaveAccessibleName('prev2AriaLabel'); expect(prev).toHaveAccessibleName('prevAriaLabel'); diff --git a/src/CenturyView.spec.jsx b/src/CenturyView.spec.jsx index 5775859f..31e76359 100644 --- a/src/CenturyView.spec.jsx +++ b/src/CenturyView.spec.jsx @@ -62,7 +62,9 @@ describe('CenturyView', () => { ); const tiles = container.querySelectorAll('.react-calendar__tile'); - const [firstDayTile, secondDayTile] = tiles; + + const firstDayTile = tiles[0]; + const secondDayTile = tiles[1]; expect(firstDayTile).toHaveClass('firstDayOfTheMonth'); expect(secondDayTile).not.toHaveClass('firstDayOfTheMonth'); @@ -75,9 +77,7 @@ describe('CenturyView', () => { , ); - const tiles = container.querySelectorAll('.react-calendar__tile'); - const [firstDayTile] = tiles; - + const firstDayTile = container.querySelector('.react-calendar__tile'); const firstDayTileContent = firstDayTile.querySelector('.testContent'); expect(firstDayTileContent).toBeInTheDocument(); @@ -103,7 +103,9 @@ describe('CenturyView', () => { ); const tiles = container.querySelectorAll('.react-calendar__tile'); - const [firstDayTile, secondDayTile] = tiles; + + const firstDayTile = tiles[0]; + const secondDayTile = tiles[1]; const firstDayTileContent = firstDayTile.querySelector('.testContent'); const secondDayTileContent = secondDayTile.querySelector('.testContent'); diff --git a/src/DecadeView.spec.jsx b/src/DecadeView.spec.jsx index 9f20cc61..1bd2b0c5 100644 --- a/src/DecadeView.spec.jsx +++ b/src/DecadeView.spec.jsx @@ -57,7 +57,9 @@ describe('DecadeView', () => { ); const tiles = container.querySelectorAll('.react-calendar__tile'); - const [firstDayTile, secondDayTile] = tiles; + + const firstDayTile = tiles[0]; + const secondDayTile = tiles[1]; expect(firstDayTile).toHaveClass('firstDayOfTheMonth'); expect(secondDayTile).not.toHaveClass('firstDayOfTheMonth'); @@ -96,7 +98,9 @@ describe('DecadeView', () => { ); const tiles = container.querySelectorAll('.react-calendar__tile'); - const [firstDayTile, secondDayTile] = tiles; + + const firstDayTile = tiles[0]; + const secondDayTile = tiles[1]; const firstDayTileContent = firstDayTile.querySelector('.testContent'); const secondDayTileContent = secondDayTile.querySelector('.testContent'); diff --git a/src/MonthView.spec.jsx b/src/MonthView.spec.jsx index a48026bd..113c1abc 100644 --- a/src/MonthView.spec.jsx +++ b/src/MonthView.spec.jsx @@ -65,7 +65,9 @@ describe('MonthView', () => { ); const tiles = container.querySelectorAll('.react-calendar__tile'); - const [firstDayTile, secondDayTile] = tiles; + + const firstDayTile = tiles[0]; + const secondDayTile = tiles[1]; expect(firstDayTile).toHaveClass('firstDayOfTheMonth'); expect(secondDayTile).not.toHaveClass('firstDayOfTheMonth'); @@ -104,7 +106,9 @@ describe('MonthView', () => { ); const tiles = container.querySelectorAll('.react-calendar__tile'); - const [firstDayTile, secondDayTile] = tiles; + + const firstDayTile = tiles[0]; + const secondDayTile = tiles[1]; const firstDayTileContent = firstDayTile.querySelector('.testContent'); const secondDayTileContent = secondDayTile.querySelector('.testContent'); diff --git a/src/MonthView/WeekNumbers.spec.jsx b/src/MonthView/WeekNumbers.spec.jsx index 91f50212..0dc1512d 100644 --- a/src/MonthView/WeekNumbers.spec.jsx +++ b/src/MonthView/WeekNumbers.spec.jsx @@ -110,9 +110,9 @@ describe('.react-calendar__month-view__weekNumbers', () => { />, ); - const children = container.querySelectorAll('button.react-calendar__tile'); + const firstChild = container.querySelector('button.react-calendar__tile'); + fireEvent.click(firstChild); - fireEvent.click(children[0]); expect(onClickWeekNumber).toHaveBeenCalledWith(52, new Date(2016, 11, 26), expect.any(Object)); }); @@ -122,9 +122,9 @@ describe('.react-calendar__month-view__weekNumbers', () => { , ); - const children = container.querySelectorAll('button.react-calendar__tile'); + const firstChild = container.querySelector('button.react-calendar__tile'); + fireEvent.click(firstChild); - fireEvent.click(children[0]); expect(onClickWeekNumber).toHaveBeenCalledWith(1, new Date(2017, 0, 1), expect.any(Object)); }); }); diff --git a/src/MonthView/Weekdays.spec.jsx b/src/MonthView/Weekdays.spec.jsx index 54c5228a..b9c511fd 100644 --- a/src/MonthView/Weekdays.spec.jsx +++ b/src/MonthView/Weekdays.spec.jsx @@ -36,8 +36,7 @@ describe('Weekdays', () => { it('renders weekdays with custom weekdays formatting', () => { const { container } = render( 'Wkdy'} />); - const weekdays = container.querySelectorAll('.react-calendar__month-view__weekdays__weekday'); - const firstWeekday = weekdays[0]; + const firstWeekday = container.querySelector('.react-calendar__month-view__weekdays__weekday'); expect(firstWeekday).toHaveTextContent('Wkdy'); }); @@ -45,10 +44,9 @@ describe('Weekdays', () => { it('renders weekdays with custom weekdays formatting', () => { const { container } = render( 'Weekday'} />); - const weekdays = container.querySelectorAll('.react-calendar__month-view__weekdays__weekday'); - const firstWeekday = weekdays[0]; - const abbr = firstWeekday.querySelector('abbr'); + const firstWeekday = container.querySelector('.react-calendar__month-view__weekdays__weekday'); + const firstWeekdayAbbr = firstWeekday.querySelector('abbr'); - expect(abbr).toHaveAccessibleName('Weekday'); + expect(firstWeekdayAbbr).toHaveAccessibleName('Weekday'); }); }); diff --git a/src/YearView.spec.jsx b/src/YearView.spec.jsx index cb3cd598..13688b12 100644 --- a/src/YearView.spec.jsx +++ b/src/YearView.spec.jsx @@ -56,7 +56,9 @@ describe('YearView', () => { ); const tiles = container.querySelectorAll('.react-calendar__tile'); - const [firstDayTile, secondDayTile] = tiles; + + const firstDayTile = tiles[0]; + const secondDayTile = tiles[1]; expect(firstDayTile).toHaveClass('firstDayOfTheMonth'); expect(secondDayTile).not.toHaveClass('firstDayOfTheMonth'); @@ -95,7 +97,9 @@ describe('YearView', () => { ); const tiles = container.querySelectorAll('.react-calendar__tile'); - const [firstDayTile, secondDayTile] = tiles; + + const firstDayTile = tiles[0]; + const secondDayTile = tiles[1]; const firstDayTileContent = firstDayTile.querySelector('.testContent'); const secondDayTileContent = secondDayTile.querySelector('.testContent');