Skip to content

Commit

Permalink
docs: remove redundant description (#1025)
Browse files Browse the repository at this point in the history
Co-authored-by: jpliu6 <jpliu6@iflytek.com>
  • Loading branch information
jp-liu and jpliu6 committed Mar 25, 2022
1 parent 16d65a7 commit f4f26cb
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ For compatibility with Jest, `TestFunction` can also be of type `(done: DoneCall
- **Type:** `(cases: ReadonlyArray<T>) => void`
- **Alias:** `it.each`

Use `test.each` when you need to run the same test with different variables.
Use `test.each` when you need to run the same test with different variables.
You can use `%i` or `%s` in the test name in the order of the test function parameters.
```ts
test.each([
Expand All @@ -148,16 +148,16 @@ When you use `test` in the top level of file, they are collected as part of the
isActive: true,
age: 32,
}

describe('person', () => {
test('person is defined', () => {
expect(person).toBeDefined()
})

test('is active', () => {
expect(person.isActive).toBeTruthy()
})

test('age limit', () => {
expect(person.age).toBeLessThanOrEqual(32)
})
Expand All @@ -172,7 +172,7 @@ When you use `test` in the top level of file, they are collected as part of the
const numberToCurrency = (value) => {
if (typeof value !== 'number')
throw new Error('Value must be a number')

return value.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}

Expand All @@ -182,7 +182,7 @@ When you use `test` in the top level of file, they are collected as part of the
expect(() => numberToCurrency('abc')).toThrow()
})
})

describe('given a valid number', () => {
test('returns the correct currency format', () => {
expect(numberToCurrency(10000)).toBe('10,000.00')
Expand Down Expand Up @@ -221,7 +221,7 @@ When you use `test` in the top level of file, they are collected as part of the
assert.equal(Math.sqrt(4), 3)
})
})

describe('other suite', () => {
// ... will be skipped
})
Expand Down Expand Up @@ -354,7 +354,7 @@ TODO
test.fails('decimals are not equal in javascript', () => {
expect(0.2 + 0.1).toBe(0.3) // 0.2 + 0.1 is 0.30000000000000004
})

test('decimals are rounded to 5 after the point', () => {
// 0.2 + 0.1 is 0.30000 | "000000000004" removed
expect(0.2 + 0.1).toBeCloseTo(0.3, 5)
Expand Down Expand Up @@ -692,7 +692,7 @@ TODO
test('toHaveLength', () => {
expect('abc').toHaveLength(3)
expect([1, 2, 3]).toHaveLength(3)

expect('').not.toHaveLength(3) // doesn't have .length of 3
expect({ length: 3 }).toHaveLength(3)
})
Expand Down Expand Up @@ -823,7 +823,7 @@ TODO

`toThrowError` asserts if a function throws an error when it is called.

For example, if we want to test that `getFruitStock('pineapples')` throws, because pineapples is not good for people with diabetes, we could write:
For example, if we want to test that `getFruitStock('pineapples')` throws, we could write:

You can provide an optional argument to test that a specific error is thrown:

Expand All @@ -840,7 +840,7 @@ TODO
function getFruitStock(type) {
if (type === 'pineapples')
throw new DiabetesError('Pineapples is not good for people with diabetes')

// Do some other stuff
}

Expand Down Expand Up @@ -917,7 +917,7 @@ TODO
function buyApples(id) {
if (!id)
throw new Error('no id')

}

test('buyApples throws an error when no id provided', async() => {
Expand Down Expand Up @@ -1259,7 +1259,7 @@ Vitest provides utility functions to help you out through it's **vi** helper. Yo
console.log(++i)
if (i === 2)
clearInterval(interval)

}, 50)

vi.runAllTimers()
Expand Down Expand Up @@ -1352,13 +1352,13 @@ Vitest provides utility functions to help you out through it's **vi** helper. Yo
```ts
const mockFn = vi.fn().mockImplementation(apples => apples + 1)
// or: vi.fn(apples => apples + 1);

const NelliesBucket = mockFn(0)
const BobsBucket = mockFn(1)

NelliesBucket === 1 // true
BobsBucket === 2 // true

mockFn.mock.calls[0][0] === 0 // true
mockFn.mock.calls[1][0] === 1 // true
```
Expand All @@ -1374,7 +1374,7 @@ Vitest provides utility functions to help you out through it's **vi** helper. Yo
.fn()
.mockImplementationOnce(() => true)
.mockImplementationOnce(() => false)

myMockFn() // true
myMockFn() // false
```
Expand All @@ -1386,7 +1386,7 @@ Vitest provides utility functions to help you out through it's **vi** helper. Yo
.fn(() => 'default')
.mockImplementationOnce(() => 'first call')
.mockImplementationOnce(() => 'second call')

// 'first call', 'second call', 'default', 'default'
console.log(myMockFn(), myMockFn(), myMockFn(), myMockFn())
```
Expand All @@ -1400,7 +1400,7 @@ Vitest provides utility functions to help you out through it's **vi** helper. Yo
```ts
test('async test', async() => {
const asyncMock = vi.fn().mockRejectedValue(new Error('Async error'))

await asyncMock() // throws "Async error"
})
```
Expand All @@ -1417,7 +1417,7 @@ Vitest provides utility functions to help you out through it's **vi** helper. Yo
.fn()
.mockResolvedValueOnce('first call')
.mockRejectedValueOnce(new Error('Async error'))

await asyncMock() // first call
await asyncMock() // throws "Async error"
})
Expand Down Expand Up @@ -1450,7 +1450,7 @@ Vitest provides utility functions to help you out through it's **vi** helper. Yo
```ts
test('async test', async() => {
const asyncMock = vi.fn().mockResolvedValue(43)

await asyncMock() // 43
})
```
Expand All @@ -1468,7 +1468,7 @@ Vitest provides utility functions to help you out through it's **vi** helper. Yo
.mockResolvedValue('default')
.mockResolvedValueOnce('first call')
.mockResolvedValueOnce('second call')

await asyncMock() // first call
await asyncMock() // second call
await asyncMock() // default
Expand Down Expand Up @@ -1508,7 +1508,7 @@ Vitest provides utility functions to help you out through it's **vi** helper. Yo
.mockReturnValue('default')
.mockReturnValueOnce('first call')
.mockReturnValueOnce('second call')

// 'first call', 'second call', 'default', 'default'
console.log(myMockFn(), myMockFn(), myMockFn(), myMockFn())
```
Expand Down

0 comments on commit f4f26cb

Please sign in to comment.