Skip to main content

dataTestNameToSelector

This function takes a data test selector with our custom syntax and transforms it into a standard css selector.

Example

const customSelector = '{navigation-item}'

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

With the dhis2DataTestPrefix env variable set to dhis2-libname:

const customSelector = '{navigation-item}'

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

With a custom prefix:

const customSelector = '{navigation-item}'

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

Arguments

dataTestName
Type: String
An individual 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 valid css data-test attribute selector