Jasmine expect
statements can produce worthless error messages like:
Expected true to be false.
To address this, matchers allow you to add a clarifying message as a second argument, expectationFailedOutput
:
toBe(expected: any, expectationFailOutput?: any): Promise<void>;
This allows you to write:
expect(await password.isDisplayed).toBe(true, "Password field should be visible");
expect(await password.isDisplayed).toBe(true, "Password field was not visible");
These will produce the following error messages, respectively:
Expected false to be true, 'Password field should be visible'.
Expected false to be true, 'Password field was not visible'.
Note, that these lines are the same except that in the first case, I described what the expect was testing for, and in the second, I describe what actually happened.
Obviously, I should choose one these conventions and use it consistently in my code base, but I can't find anything in the documentation about what the typical convention is. Should the message describe what we expected to happen, or should it describe what did happen?
If the Jasmine team doesn't have a convention for this, perhaps somebody who's worked on a lot of Jasmine projects knows what the typical convention is.