adobe / adobe/aio-lib-files

global error tests should be rewritten as expect extentions

Open
#64 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
13
Forks
10
PR merge metrics
No merged PRs in 30d

Description

We have numerous instances of global.expect...
```
// eslint-disable-next-line jest/expect-expect
test('when path is not a valid string', async () => {
await global.expectToThrowBadArg(files.delete.bind(files, 123), ['filePath', 'string'], { filePath: 123, options: {} })
})
```
This means, we need to have many, many `eslint-disable-next-line jest/expect-expect`

A better practice, and the jest recommended way is to define our own expect extensions
```
expect.extend({
toThrowBadArg: ( words, options ) => {
// more expectations here ...
}
})

// then tests call it like this:
expect(files.delete.bind(files, 123)).toThrowBadArg( ['filePath', 'string'], { filePath: 123, options: {} })

```

If we do this well, they can be reused across multiple repo/libs

Contributor guide

Open the contributing guide

Research direction

Locate the tests using global.expect and the repeated eslint-disable-next-line jest/expect-expect comments. Read the existing Jest test setup and the global error helpers first, then determine the shared expect extensions needed for the current error assertions. Done means the affected tests use the Jest extension style, retain their coverage, and no longer need those disables.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.