Implementation:Webdriverio Webdriverio ESLint AwaitExpect
| Knowledge Sources | |
|---|---|
| Domains | Linting, Test_Quality |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
ESLint rule that enforces the use of await before WebdriverIO expect statements to prevent unhandled asynchronous assertions.
Description
The await-expect rule is defined as a Rule.RuleModule and categorized as a "problem" type ESLint rule. It inspects CallExpression AST nodes to determine whether an expect call is chained with a recognized WebdriverIO matcher (such as toBeDisplayed, toHaveText, toExist, etc. from the MATCHERS constant). If the expect-matcher call appears as a bare ExpressionStatement (i.e., without an await prefix), the rule reports a missingAwait error. This ensures that all WebdriverIO assertion promises are properly awaited, preventing silent test passes.
Usage
Use this rule in any WebdriverIO test project by enabling it in your ESLint configuration. It is particularly important in projects using WebdriverIO's asynchronous expect API where forgetting await would cause assertions to be silently skipped, leading to false-positive test results.
Code Reference
Source Location
- Repository: Webdriverio_Webdriverio
- File: packages/eslint-plugin-wdio/src/rules/await-expect.ts
Signature
const rule: Rule.RuleModule = {
meta: {
type: 'problem',
docs: {
description: 'expect must be prefixed with await',
category: 'Possible Errors',
recommended: false,
},
messages: {
missingAwait: 'Missing await before an expect statement'
},
hasSuggestions: true
},
create: function (context: Rule.RuleContext): Rule.RuleListener
}
export default rule
Import
import rule from '@wdio/eslint-plugin-wdio/src/rules/await-expect'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| context | Rule.RuleContext | Yes | ESLint rule context providing the AST and reporting API |
| node | CallExpression | Yes | AST node representing a function call expression to be validated |
Outputs
| Name | Type | Description |
|---|---|---|
| Rule.RuleListener | object | Listener object with a CallExpression visitor that reports missingAwait when an expect-matcher chain lacks await |
Usage Examples
// .eslintrc.js configuration
module.exports = {
plugins: ['wdio'],
rules: {
'wdio/await-expect': 'error'
}
}
// Incorrect - will trigger the rule
expect(el).toBeDisplayed()
// Correct - properly awaited
await expect(el).toBeDisplayed()
await expect(browser).toHaveUrl('https://example.com')