blob: 47ba72345cef6ea6219afcd9dcda7c86a2cc081f [file] [log] [blame] [view]
TypeScript Team64a61732018-02-05 20:36:51 +01001<!-- FIXME(alexeagle): generate the docs from the sources -->
2
3## Don't expect promises toBeTruthy()
4
5Don't write expectations like this:
6
7 expect(returnsPromise()).toBeTruthy();
8
9Promises are always truthy, so this assertion will never fail. Usually, the
10intention was to match the result of the promise. If that's the case, simply
11add an `await`.
12
13 expect(await returnsPromise()).toBeTruthy();
14
15### In Protractor tests
16
17If you're not writing a Protractor test, you can safely ignore this section.
18
19In the past, Protractor tests have patched `expect()` to automatically unwrap
20promises, which made these assertions work as expected without needing an
21`await`. However, the [control flow is deprecated][1] and will be removed in
22Selenium WebDriver 4.0, and these assertions are now a bug. You'll
23need to `await` the promise as above.
24
25If you can't `await` the promise because your tests need the control flow, you
26can use a more specific matcher.
27
28 expect(returnsPromise()).toBe(true);
29
30This assertion will work as expected for now and will fail when the control flow
31is finally removed.
32
33[1]: https://github.com/SeleniumHQ/selenium/issues/2969