Skip to content

Commit

Permalink
added rule (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
YevhS authored Feb 23, 2024
1 parent 08891e4 commit 79ae8b4
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions e2e-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
- [4.1 One assertion per one test step method](#41-one-assertion-per-one-test-step-method)
- [4.2 Use expect for assertions](#42-use-expect-for-assertions)
- [5\. Files naming](#3-files-naming)
- [5.1. Name test files without should at the beggining](#51-name-test-files-without-should-at-the-beggining)

- [5.1. Name test files without should at the beginning](#51-name-test-files-without-should-at-the-beggining)
- [6\. Class methods with conditional logic](#6-class-methods-with-conditional-logic)
- [6.1. Use ternary operator for conditional logic ](#61-use-ternary-operator-for-conditional-logic)

1\. Factory classes
--------------
Expand Down Expand Up @@ -517,3 +518,43 @@ To make file name shorter, try to avoid using the `should` word at the beginning
- `shouldBeAbleToEditOwnUserProfile` > `editOwnUserProfile`
- `shouldBeAbleToChangeTheCourse` > `courseChanging`
- `shouldUpdateUsername` > `updateUsername`

6\. Class methods with conditional logic
--------------

#### 6.1. Use ternary operator for conditional logic

Use ternary operator for conditional logic instead of if-else statement because it's more concise and readable.

```typescript
// ❌ not recommended
export class CourseViewPage extends LMSEditorBasePage {
async assertModuleListItemIsVisible(name?: string): Promise<void> {
await test.step('Assert module list item is visible', async () => {
if (name) {
const moduleListItem = this.listItem.filter({hasText: name});

await expect(moduleListItem).toBeVisible();

return;
}

await expect(this.listItem).toBeVisible();
});
}
}

// ✅ recommended
export class CourseViewPage extends LMSEditorBasePage {
async assertModuleListItemIsVisible(name?: string): Promise<void> {
await test.step('Assert module list item is visible', async () => {
const moduleListItem = name
? this.listItem.filter({hasText: name})
: this.listItem;

await expect(moduleListItem).toBeVisible();
});
}
}

```

0 comments on commit 79ae8b4

Please sign in to comment.