11import React from 'react' ;
2+ import moment from 'moment' ;
3+
24import { render , screen } from '@testing-library/react' ;
35import userEvent from '@testing-library/user-event' ;
4- import moment from 'moment' ;
6+
57import TwoMonthPicker from '../two-month-picker' ;
68
79describe ( 'TwoMonthPicker' , ( ) => {
@@ -18,17 +20,17 @@ describe('TwoMonthPicker', () => {
1820 const currentYear = moment ( ) . format ( 'YYYY' ) ;
1921 expect ( screen . getByText ( prevMonth ) ) . toBeInTheDocument ( ) ;
2022 expect ( screen . getByText ( currentMonth ) ) . toBeInTheDocument ( ) ;
21- expect ( screen . getAllByText ( currentYear ) ) . toHaveLength ( 2 ) ;
23+ expect ( screen . getByText ( currentYear ) ) . toBeInTheDocument ( ) ;
2224 } ) ;
23- it ( 'should call onChange when a date is selected' , ( ) => {
25+ it ( 'should call onChange when a date is selected' , async ( ) => {
2426 render ( < TwoMonthPicker { ...mockProps } /> ) ;
2527 const prevMonthDate = moment ( ) . date ( 1 ) . subtract ( 1 , 'month' ) ;
2628 const prevMonthDateElement = screen . getAllByText ( prevMonthDate . date ( ) ) [ 0 ] ;
2729 const prevMonthFullDate = prevMonthDate . format ( 'YYYY-MM-DD' ) ;
28- userEvent . click ( prevMonthDateElement ) ;
30+ await userEvent . click ( prevMonthDateElement ) ;
2931 expect ( mockProps . onChange ) . toHaveBeenCalledWith ( moment . utc ( prevMonthFullDate , 'YYYY-MM-DD' ) ) ;
3032 } ) ;
31- it ( 'should jump to current month from previous months upon clicking today button' , ( ) => {
33+ it ( 'should jump to current month from previous months upon clicking today button' , async ( ) => {
3234 render ( < TwoMonthPicker { ...mockProps } /> ) ;
3335 const currentMonth = moment ( ) . format ( 'MMM' ) ;
3436 const monthBeforePrevious = moment ( ) . subtract ( 2 , 'month' ) . format ( 'MMM' ) ;
@@ -37,12 +39,12 @@ describe('TwoMonthPicker', () => {
3739 const todayButton = screen . getByTestId ( 'dt_calendar_icon_IcCalendarForwardToday' ) ;
3840
3941 // go to previous months
40- userEvent . click ( prevMonthButton ) ;
42+ await userEvent . click ( prevMonthButton ) ;
4143 expect ( screen . getByText ( monthBeforePrevious ) ) . toBeInTheDocument ( ) ;
4244 expect ( screen . getByText ( prevMonth ) ) . toBeInTheDocument ( ) ;
4345
4446 // jump to current month
45- userEvent . click ( todayButton ) ;
47+ await userEvent . click ( todayButton ) ;
4648 expect ( screen . queryByText ( monthBeforePrevious ) ) . not . toBeInTheDocument ( ) ;
4749 expect ( screen . getByText ( prevMonth ) ) . toBeInTheDocument ( ) ;
4850 expect ( screen . getByText ( currentMonth ) ) . toBeInTheDocument ( ) ;
0 commit comments