Testing Spaceweb components

This guide will help you with understanding how to test certain spaceweb components.

Testing Combobox

Select

Select Subtext
AliceBlue
Selected AliceBlue.
open
Select caption

To test the which value is selected in the combobox example above, we can use getSelectedOptions utility provided in spaceweb/select. We can chose to pass the container of the Combobox to this utility as the first argument. If container is not provided, this utility will use the screen object provided by react-testing-library as the default container. This utility will search for all the elements within the container with data-testid=combobox-selected-value and return the testContent of these elements as a string array which can be used for testing.

import { getSelectedOptions } from '@sprinklrjs/spaceweb/select/utils/test-utils';
test("AliceBlue should be the selected option", () => {
expect(getSelectedOptions()).toEqual(["AliceBlue"])
// no container passed so screen will be used as container
})