One of my test expects an error message text to be one of multiple values. Since getText()
returns a promise I cannot use toContain()
jasmine matcher. The following would not work since protractor
(jasminewd
under-the-hood) would not resolve a promise in the second part of the matcher, toContain()
in this case:
expect(["Unknown Error", "Connection Error"]).toContain(page.errorMessage.getText());
Question: Is there a way to check if an element is in an array with jasmine+protractor where an element is a promise?
In other words, I'm looking for inverse of toContain()
so that the expect()
would implicitly resolve the promise passed in.
As a workaround, I can explicitly resolve the promise with then()
:
page.errorMessage.getText().then(function (text) {
expect(["Unknown Error", "Connection Error"]).toContain(text);
});
I'm not sure if this is the best option. I would also be okay with a solution based on third-parties like jasmine-matchers
.
As an example, this kind of assertion exists in Python:
self.assertIn(1, [1, 2, 3, 4])
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…