1

I'm writing a protractor test which asserts a URL against two different browser URLs.

I tried using toMatch with a regular expression but I get an error.

Is it possible to assert an actual string value against 2 or more expected string values and see if it is equal to any of them?

expect(url1).toMatch(/this.url|www.google.com/);
Svante
  • 50,694
  • 11
  • 78
  • 122
Aprilgirl
  • 31
  • 3

1 Answers1

0

Sounds like you want to use toContain() which works for finding an item in an array. So switch your assertion around because you want to pass it an array of URLs [this.url, 'www.google.com'] and assert that it will contain url1.

expect([this.url, 'www.google.com']).toContain(url1);

Note: While this should work, personally I don't like to have my values on the receiving end of the assertion i.e. toContain(url1), I would rather that be passed first expect(url1).... However, in the end it's still asserting actual vs expected values so not a huge deal in my opinion.

https://jasmine.github.io/2.0/introduction.html

Gunderson
  • 3,263
  • 2
  • 16
  • 34
  • Thank you for the help. I got it work by using the other way some thing like this and it works.. ! expect(this.currentURL).toContain((url1|| 'www.google.com')); – Aprilgirl Oct 17 '17 at 09:25