I need to verify the text label but it contains dynamic part, so I try to use regex but it doesn't work.
expect(aboutPage.userInterfaceText.getText()).toMatch('/- User Interface: v \d+\.\d+\.\d+/');
I always get next error:
- Expected '- User Interface: v 4.4.63' to match '/- User Interface: v d+.d+.d+/'.
- Expected '- User Interface: v 4.4.63' to match '/- User Interface: v d+.d+.d+/'.
As you can see the slashes at both ends of the pattern are also included into the expression, but your - User Interface: v 4.4.63
test string does not contain the slashes.
You should not enclose the regular expression in the single quotes to make it a valid regular expression object:
expect(aboutPage.userInterfaceText.getText()).toMatch(/- User Interface: v \d+\.\d+\.\d+/);
Works for me on the console:
> var s = "- User Interface: v 4.4.63";
> var re = /- User Interface: v \d+\.\d+\.\d+/;
> s.match(re)
["- User Interface: v 4.4.63"]
You need to convert the pattern to string then you can use the match() to check the regex matchers
expect(control.errors.pattern.requiredPattern).toString().match('^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\S\./0-9]*$');
or like this
expect(control.errors.pattern.requiredPattern).toString().match(/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\S\./0-9]*$/);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With