In my JavaScript program, I have a Mocha test that checks if all available currencies are displayed in a drop-down list:
it('displays all available currencies in drop down list', () => {
return invoiceEditPage.details.currencyDropDown.dropDown.waitForEnabled()
.then(() => invoiceEditPage.details.currencyDropDown.click())
.then(() => getEnabledCurrencies(tenantUsers.admin.authUser))
.then((listOfCurrencies) => console.log(listOfCurrencies["name"].split(",")))
//.then((listOfCurrencies) => this.getCurrencyFromJSON(listOfCurrencies))
//.then(() => console.log(invoiceEditPage.details.currencyDropDown.dropDownContents))
//.then((listOfCurrencies) => assert.strictEqual(listOfCurrencies, invoiceEditPage.details.currencyDropDown.dropDownContents))
.then(() => invoiceEditPage.details.currencyDropDown.dropDownMask.click());
});
When I use the following line:
.then((listOfCurrencies) => console.log(listOfCurrencies))
I see a JSON string being printed out like this:
[ { displayText: 'USD$',
name: 'US Dollar',
symbol: 'USD$' },
and so on.
My goal is to extract an array of strings containing the names of all the JSON objects, for example:
["US Dollar", "Canadian Dollar", "Australian Dollar"]
.
However, when using the above line, I encounter an error message stating:
"undefined: Cannot read property 'split' of undefined"
Even after trying JSON.parse(), I receive an Unexpected token o error, indicating that "listOfCurrencies" is already a string. Can anyone help me understand what's causing this issue?
Thank you