Files
ai-course/node_modules/eslint-plugin-jest/docs/rules/prefer-expect-resolves.md
KQL ce6aa207e9 fix: 修复图片路径以适配GitHub Pages base path
- 将所有图片路径从绝对路径改为使用 process.env.PUBLIC_URL
- 修复 HomePage.tsx 中所有图片引用
- 修复 CoursePage.tsx 中所有图片引用
- 确保图片在 GitHub Pages 上正确加载

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 09:24:45 +08:00

54 lines
1.4 KiB
Markdown

# Prefer `await expect(...).resolves` over `expect(await ...)` syntax (`prefer-expect-resolves`)
When working with promises, there are two primary ways you can test the resolved
value:
1. use the `resolve` modifier on `expect`
(`await expect(...).resolves.<matcher>` style)
2. `await` the promise and assert against its result
(`expect(await ...).<matcher>` style)
While the second style is arguably less dependent on `jest`, if the promise
rejects it will be treated as a general error, resulting in less predictable
behaviour and output from `jest`.
Additionally, favoring the first style ensures consistency with its `rejects`
counterpart, as there is no way of "awaiting" a rejection.
## Rule details
This rule triggers a warning if an `await` is done within an `expect`, and
recommends using `resolves` instead.
Examples of **incorrect** code for this rule
```js
it('passes', async () => {
expect(await someValue()).toBe(true);
});
it('is true', async () => {
const myPromise = Promise.resolve(true);
expect(await myPromise).toBe(true);
});
```
Examples of **correct** code for this rule
```js
it('passes', async () => {
await expect(someValue()).resolves.toBe(true);
});
it('is true', async () => {
const myPromise = Promise.resolve(true);
await expect(myPromise).resolves.toBe(true);
});
it('errors', async () => {
await expect(Promise.rejects('oh noes!')).rejects.toThrow('oh noes!');
});
```