Skip to main content

parseSelectorWithDataTest

Example

const customSelector = '{navigation-item}:first-child {link-text}'

// Will return:
// '[data-test="navigation-item"]:first-child [data-test="link-text"]'
const validCssSelector = dataTestNameToSelector(customSelector)

With the dhis2DataTestPrefix env variable set to dhis2-libname:

const customSelector = '{navigation-item}:first-child {link-text}'

// Will return:
// '[data-test="dhis2-libname-navigation-item"]:first-child [data-test="dhis2-libname-link-text"]'
const validCssSelector = dataTestNameToSelector(customSelector)

With a custom prefix:

const customSelector = '{navigation-item}:first-child {link-text}'

// Will return:
// '[data-test="custom-prefix-navigation-item"]:first-child [data-test="custom-prefix-link-text"]'
const validCssSelector = dataTestNameToSelector(customSelector, 'custom-prefix')

Arguments

selector
Type: String
A data test selector with custom syntax.

prefix
Type: String
An optional prefix. By default the function uses the dhis2DataTestPrefix environment variable or use an empty string when the env var has not been set.


Returns
Type: String
The whole valid css selector with valid data-test selectors