API reference for Angular Material datepicker-testing

import {MatDatepickerInputHarness} from '@angular/material/datepicker/testing';

Harness for interacting with a standard Material datepicker inputs in tests.

Properties
Name Description

static hostSelector: '.mat-datepicker-input'

Methods
blur

Blurs the input and returns a promise that indicates when the action is complete.

Returns
Promise<void>

async
closeCalendar

Closes the calendar associated with the input.

Returns
Promise<void>

Promise that resolves when the action completes.

focus

Focuses the input and returns a promise that indicates when the action is complete.

Returns
Promise<void>

async
getCalendar

Gets the MatCalendarHarness that is associated with the trigger.

Parameters

filter

CalendarHarnessFilters = {}

Returns
Promise<MatCalendarHarness>

getMax

Gets the formatted maximum date for the input's value.

Returns
Promise<string | null>

getMin

Gets the formatted minimum date for the input's value.

Returns
Promise<string | null>

getPlaceholder

Gets the placeholder of the input.

Returns
Promise<string>

getValue

Gets the value of the input.

Returns
Promise<string>

async
hasCalendar

Whether a calendar is associated with the input.

Returns
Promise<boolean>

async
host

Gets a Promise for the TestElement representing the host element of the component.

Returns
Promise<TestElement>

async
isCalendarOpen

Gets whether the calendar associated with the input is open.

Returns
Promise<boolean>

isDisabled

Whether the input is disabled.

Returns
Promise<boolean>

isFocused

Whether the input is focused.

Returns
Promise<boolean>

isRequired

Whether the input is required.

Returns
Promise<boolean>

async
openCalendar

Opens the calendar associated with the input.

Returns
Promise<void>

Promise that resolves when the action completes.

setValue

Sets the value of the input. The value will be set by simulating keypresses that correspond to the given value.

Parameters

newValue

string

Returns
Promise<void>

static
with

Gets a HarnessPredicate that can be used to search for a MatDatepickerInputHarness that meets certain criteria.

Parameters

options

DatepickerInputHarnessFilters = {}

Returns
HarnessPredicate<MatDatepickerInputHarness>

a HarnessPredicate configured with the given options.

Harness for interacting with a standard Material datepicker toggle in tests.

Properties
Name Description

static hostSelector: '.mat-datepicker-toggle'

Methods
closeCalendar

Closes the calendar if it is open.

Returns
Promise<void>

getCalendar

Gets the MatCalendarHarness that is associated with the trigger.

Parameters

filter

CalendarHarnessFilters = {}

Returns
Promise<MatCalendarHarness>

hasCalendar

Gets whether there is a calendar associated with the trigger.

Returns
Promise<boolean>

async
host

Gets a Promise for the TestElement representing the host element of the component.

Returns
Promise<TestElement>

async
isCalendarOpen

Gets whether the calendar associated with the toggle is open.

Returns
Promise<boolean>

async
isDisabled

Whether the toggle is disabled.

Returns
Promise<boolean>

openCalendar

Opens the calendar if the trigger is enabled and it has a calendar.

Returns
Promise<void>

static
with

Gets a HarnessPredicate that can be used to search for a MatDatepickerToggleHarness that meets certain criteria.

Parameters

options

DatepickerToggleHarnessFilters = {}

Returns
HarnessPredicate<MatDatepickerToggleHarness>

a HarnessPredicate configured with the given options.

Harness for interacting with a standard Material date range start input in tests.

Properties
Name Description

static hostSelector: '.mat-start-date'

Methods
blur

Blurs the input and returns a promise that indicates when the action is complete.

Returns
Promise<void>

focus

Focuses the input and returns a promise that indicates when the action is complete.

Returns
Promise<void>

getMax

Gets the formatted maximum date for the input's value.

Returns
Promise<string | null>

getMin

Gets the formatted minimum date for the input's value.

Returns
Promise<string | null>

getPlaceholder

Gets the placeholder of the input.

Returns
Promise<string>

getValue

Gets the value of the input.

Returns
Promise<string>

async
host

Gets a Promise for the TestElement representing the host element of the component.

Returns
Promise<TestElement>

isDisabled

Whether the input is disabled.

Returns
Promise<boolean>

isFocused

Whether the input is focused.

Returns
Promise<boolean>

isRequired

Whether the input is required.

Returns
Promise<boolean>

setValue

Sets the value of the input. The value will be set by simulating keypresses that correspond to the given value.

Parameters

newValue

string

Returns
Promise<void>

static
with

Gets a HarnessPredicate that can be used to search for a MatStartDateHarness that meets certain criteria.

Parameters

options

DatepickerInputHarnessFilters = {}

Returns
HarnessPredicate<MatStartDateHarness>

a HarnessPredicate configured with the given options.

Harness for interacting with a standard Material date range end input in tests.

Properties
Name Description

static hostSelector: '.mat-end-date'

Methods
blur

Blurs the input and returns a promise that indicates when the action is complete.

Returns
Promise<void>

focus

Focuses the input and returns a promise that indicates when the action is complete.

Returns
Promise<void>

getMax

Gets the formatted maximum date for the input's value.

Returns
Promise<string | null>

getMin

Gets the formatted minimum date for the input's value.

Returns
Promise<string | null>

getPlaceholder

Gets the placeholder of the input.

Returns
Promise<string>

getValue

Gets the value of the input.

Returns
Promise<string>

async
host

Gets a Promise for the TestElement representing the host element of the component.

Returns
Promise<TestElement>

isDisabled

Whether the input is disabled.

Returns
Promise<boolean>

isFocused

Whether the input is focused.

Returns
Promise<boolean>

isRequired

Whether the input is required.

Returns
Promise<boolean>

setValue

Sets the value of the input. The value will be set by simulating keypresses that correspond to the given value.

Parameters

newValue

string

Returns
Promise<void>

static
with

Gets a HarnessPredicate that can be used to search for a MatEndDateHarness that meets certain criteria.

Parameters

options

DatepickerInputHarnessFilters = {}

Returns
HarnessPredicate<MatEndDateHarness>

a HarnessPredicate configured with the given options.

Harness for interacting with a standard Material date range input in tests.

Properties
Name Description

static hostSelector: '.mat-date-range-input'

Methods
closeCalendar

Closes the calendar if it is open.

Returns
Promise<void>

getCalendar

Gets the MatCalendarHarness that is associated with the trigger.

Parameters

filter

CalendarHarnessFilters = {}

Returns
Promise<MatCalendarHarness>

async
getEndInput

Gets the inner start date input inside the range input.

Returns
Promise<MatEndDateHarness>

async
getSeparator

Gets the separator text between the values of the two inputs.

Returns
Promise<string>

async
getStartInput

Gets the inner start date input inside the range input.

Returns
Promise<MatStartDateHarness>

async
getValue

Gets the combined value of the start and end inputs, including the separator.

Returns
Promise<string>

hasCalendar

Gets whether there is a calendar associated with the trigger.

Returns
Promise<boolean>

async
host

Gets a Promise for the TestElement representing the host element of the component.

Returns
Promise<TestElement>

async
isCalendarOpen

Opens the calendar associated with the input.

Returns
Promise<boolean>

async
isDisabled

Gets whether the range input is disabled.

Returns
Promise<boolean>

async
isRequired

Gets whether the range input is required.

Returns
Promise<boolean>

openCalendar

Opens the calendar if the trigger is enabled and it has a calendar.

Returns
Promise<void>

static
with

Gets a HarnessPredicate that can be used to search for a MatDateRangeInputHarness that meets certain criteria.

Parameters

options

DateRangeInputHarnessFilters = {}

Returns
HarnessPredicate<MatDateRangeInputHarness>

a HarnessPredicate configured with the given options.

Harness for interacting with a standard Material calendar in tests.

Properties
Name Description

static hostSelector: '.mat-calendar'

Methods
async
changeView

Changes the calendar view by clicking on the view toggle button.

Returns
Promise<void>

Promise that resolves when the action completes.

async
getCells

Gets a list of cells inside the calendar.

Parameters

filter

CalendarCellHarnessFilters = {}

Returns
Promise<MatCalendarCellHarness[]>

async
getCurrentView

Gets the current view that is being shown inside the calendar.

Returns
Promise<CalendarView>

async
getCurrentViewLabel

Gets the label of the current calendar view.

Returns
Promise<string>

async
host

Gets a Promise for the TestElement representing the host element of the component.

Returns
Promise<TestElement>

async
next

Goes to the next page of the current view (e.g. next month when inside the month view).

Returns
Promise<void>

Promise that resolves when the action completes.

async
previous

Goes to the previous page of the current view (e.g. previous month when inside the month view).

Returns
Promise<void>

Promise that resolves when the action completes.

async
selectCell

Selects a cell in the current calendar view.

Parameters

filter

CalendarCellHarnessFilters = {}

Returns
Promise<void>

Promise that resolves when the action completes.

static
with

Gets a HarnessPredicate that can be used to search for a MatCalendarHarness that meets certain criteria.

Parameters

options

CalendarHarnessFilters = {}

Returns
HarnessPredicate<MatCalendarHarness>

a HarnessPredicate configured with the given options.

Harness for interacting with a standard Material calendar cell in tests.

Properties
Name Description

static hostSelector: '.mat-calendar-body-cell'

Methods
async
blur

Removes focus from the calendar cell.

Returns
Promise<void>

Promise that resolves when the action completes.

async
focus

Focuses the calendar cell.

Returns
Promise<void>

Promise that resolves when the action completes.

async
getAriaLabel

Gets the aria-label of the calendar cell.

Returns
Promise<string>

async
getText

Gets the text of the calendar cell.

Returns
Promise<string>

async
host

Gets a Promise for the TestElement representing the host element of the component.

Returns
Promise<TestElement>

async
hover

Hovers over the calendar cell.

Returns
Promise<void>

Promise that resolves when the action completes.

async
isActive

Whether the cell is currently activated using keyboard navigation.

Returns
Promise<boolean>

async
isComparisonRangeEnd

Whether the cell is the end of the comparison range.

Returns
Promise<boolean>

async
isComparisonRangeStart

Whether the cell is the start of the comparison range.

Returns
Promise<boolean>

async
isDisabled

Whether the cell is disabled.

Returns
Promise<boolean>

async
isInComparisonRange

Whether the cell is inside of the comparison range.

Returns
Promise<boolean>

async
isInPreviewRange

Whether the cell is inside of the preview range.

Returns
Promise<boolean>

async
isInRange

Whether the cell is part of the main range.

Returns
Promise<boolean>

async
isPreviewRangeEnd

Whether the cell is the end of the preview range.

Returns
Promise<boolean>

async
isPreviewRangeStart

Whether the cell is the start of the preview range.

Returns
Promise<boolean>

async
isRangeEnd

Whether the cell is the end of the main range.

Returns
Promise<boolean>

async
isRangeStart

Whether the cell is the start of the main range.

Returns
Promise<boolean>

async
isSelected

Whether the cell is selected.

Returns
Promise<boolean>

async
isToday

Whether the cell represents today's date.

Returns
Promise<boolean>

async
mouseAway

Moves the mouse away from the calendar cell.

Returns
Promise<void>

Promise that resolves when the action completes.

async
select

Selects the calendar cell. Won't do anything if the cell is disabled.

Returns
Promise<void>

Promise that resolves when the action completes.

static
with

Gets a HarnessPredicate that can be used to search for a MatCalendarCellHarness that meets certain criteria.

Parameters

options

CalendarCellHarnessFilters = {}

Returns
HarnessPredicate<MatCalendarCellHarness>

a HarnessPredicate configured with the given options.

A set of criteria that can be used to filter a list of datepicker input instances.

Properties
Name Description

placeholder: string | RegExp

Filters based on the placeholder text of the input.

value: string | RegExp

Filters based on the value of the input.

A set of criteria that can be used to filter a list of datepicker toggle instances.

A set of criteria that can be used to filter a list of calendar instances.

A set of criteria that can be used to filter a list of calendar cell instances.

Properties
Name Description

active: boolean

Filters based on whether the cell is activated using keyboard navigation

disabled: boolean

Filters based on whether the cell is disabled.

inComparisonRange: boolean

Filters based on whether the cell is inside of the comparison range.

inPreviewRange: boolean

Filters based on whether the cell is inside of the preview range.

inRange: boolean

Filters based on whether the cell is inside of the main range.

selected: boolean

Filters based on whether the cell is selected.

text: string | RegExp

Filters based on the text of the cell.

today: boolean

Filters based on whether the cell represents today's date.

A set of criteria that can be used to filter a list of date range input instances.

Properties
Name Description

value: string | RegExp

Filters based on the value of the input.