I'm trying to test my site navigation against what I have in a config file. I was getting a failure and determined the failure was because my config had title case but the DOM has upper case. I'd like the tests to be case agnostic as I find it easier to read a config file with title case. I'm sure I could do a .toLowerCase() or a .toUpperCase() or something, but seems to me like it would be best to try and use .match(). I'm not quite sure how to use it properly when trying to use it in a loop through object keys.
Sample Config:
"mainMenuNavTopLevel": {
"Oneword": "/path1",
"Two Words": "/path2"
},
Sample Test:
for (const [key, value] of Object.entries(config.mainMenuNavTopLevel)) {
let caseKey = key.match(/`"${key}"/i) // this doesn't seem to work
// Verify the top menu nav items displayed match the keys in the object in config
await t.expect(Header.mainMenuNavItem.withText(caseKey).exists).ok(`"${caseKey}" Main Menu Nav key does NOT match config`);
Line 24 errors with "text" argument is expected to be a string or a regular expression, but it was object.
How would I go about using match in this case? Is it even possible?
Aucun commentaire:
Enregistrer un commentaire