Bump jest to fix weird prettier bug (#2716)
Our snapshot tests have been acting strange. It turned out that there's a change in prettier that is incompatible with prettier's inline snapshots. This PR: - updates jest to a compatible alpha - updates dependencies ### Change Type - [x] `tests` — Changes to any test code only[^2] ### Test Plan - [x] Unit Tests
This commit is contained in:
parent
d3a6d91217
commit
dee5d2928c
11 changed files with 526 additions and 532 deletions
|
@ -155,26 +155,26 @@ describe('AlarmScheduler', () => {
|
||||||
|
|
||||||
// a...
|
// a...
|
||||||
await advanceTime(1000)
|
await advanceTime(1000)
|
||||||
expect(alarms.a).toBeCalledTimes(1)
|
expect(alarms.a).toHaveBeenCalledTimes(1)
|
||||||
expect(alarms.b).toBeCalledTimes(0)
|
expect(alarms.b).toHaveBeenCalledTimes(0)
|
||||||
expect(alarms.c).toBeCalledTimes(0)
|
expect(alarms.c).toHaveBeenCalledTimes(0)
|
||||||
// called for b, then a again to reschedule c:
|
// called for b, then a again to reschedule c:
|
||||||
expect(storage.setAlarm).toHaveBeenCalledTimes(3)
|
expect(storage.setAlarm).toHaveBeenCalledTimes(3)
|
||||||
expect(storage.setAlarm).toHaveBeenLastCalledWith(1_001_500)
|
expect(storage.setAlarm).toHaveBeenLastCalledWith(1_001_500)
|
||||||
|
|
||||||
// ...b...
|
// ...b...
|
||||||
await advanceTime(500)
|
await advanceTime(500)
|
||||||
expect(alarms.a).toBeCalledTimes(1)
|
expect(alarms.a).toHaveBeenCalledTimes(1)
|
||||||
expect(alarms.b).toBeCalledTimes(0)
|
expect(alarms.b).toHaveBeenCalledTimes(0)
|
||||||
expect(alarms.c).toBeCalledTimes(1)
|
expect(alarms.c).toHaveBeenCalledTimes(1)
|
||||||
expect(storage.setAlarm).toHaveBeenCalledTimes(4)
|
expect(storage.setAlarm).toHaveBeenCalledTimes(4)
|
||||||
expect(storage.setAlarm).toHaveBeenLastCalledWith(1_002_000)
|
expect(storage.setAlarm).toHaveBeenLastCalledWith(1_002_000)
|
||||||
|
|
||||||
// ...c
|
// ...c
|
||||||
await advanceTime(500)
|
await advanceTime(500)
|
||||||
expect(alarms.a).toBeCalledTimes(1)
|
expect(alarms.a).toHaveBeenCalledTimes(1)
|
||||||
expect(alarms.b).toBeCalledTimes(1)
|
expect(alarms.b).toHaveBeenCalledTimes(1)
|
||||||
expect(alarms.c).toBeCalledTimes(1)
|
expect(alarms.c).toHaveBeenCalledTimes(1)
|
||||||
expect(storage.setAlarm).toHaveBeenCalledTimes(4)
|
expect(storage.setAlarm).toHaveBeenCalledTimes(4)
|
||||||
|
|
||||||
// sequence should be a -> b -> c:
|
// sequence should be a -> b -> c:
|
||||||
|
@ -185,26 +185,26 @@ describe('AlarmScheduler', () => {
|
||||||
|
|
||||||
// a...
|
// a...
|
||||||
await advanceTime(1000)
|
await advanceTime(1000)
|
||||||
expect(alarms.a).toBeCalledTimes(2)
|
expect(alarms.a).toHaveBeenCalledTimes(2)
|
||||||
expect(alarms.b).toBeCalledTimes(1)
|
expect(alarms.b).toHaveBeenCalledTimes(1)
|
||||||
expect(alarms.c).toBeCalledTimes(1)
|
expect(alarms.c).toHaveBeenCalledTimes(1)
|
||||||
// called for b, not needed to reschedule c:
|
// called for b, not needed to reschedule c:
|
||||||
expect(storage.setAlarm).toHaveBeenCalledTimes(6)
|
expect(storage.setAlarm).toHaveBeenCalledTimes(6)
|
||||||
expect(storage.setAlarm).toHaveBeenLastCalledWith(1_004_000)
|
expect(storage.setAlarm).toHaveBeenLastCalledWith(1_004_000)
|
||||||
|
|
||||||
// ...b...
|
// ...b...
|
||||||
await advanceTime(1000)
|
await advanceTime(1000)
|
||||||
expect(alarms.a).toBeCalledTimes(2)
|
expect(alarms.a).toHaveBeenCalledTimes(2)
|
||||||
expect(alarms.b).toBeCalledTimes(2)
|
expect(alarms.b).toHaveBeenCalledTimes(2)
|
||||||
expect(alarms.c).toBeCalledTimes(1)
|
expect(alarms.c).toHaveBeenCalledTimes(1)
|
||||||
expect(storage.setAlarm).toHaveBeenCalledTimes(7)
|
expect(storage.setAlarm).toHaveBeenCalledTimes(7)
|
||||||
expect(storage.setAlarm).toHaveBeenLastCalledWith(1_005_000)
|
expect(storage.setAlarm).toHaveBeenLastCalledWith(1_005_000)
|
||||||
|
|
||||||
// ...c
|
// ...c
|
||||||
await advanceTime(1000)
|
await advanceTime(1000)
|
||||||
expect(alarms.a).toBeCalledTimes(2)
|
expect(alarms.a).toHaveBeenCalledTimes(2)
|
||||||
expect(alarms.b).toBeCalledTimes(2)
|
expect(alarms.b).toHaveBeenCalledTimes(2)
|
||||||
expect(alarms.c).toBeCalledTimes(2)
|
expect(alarms.c).toHaveBeenCalledTimes(2)
|
||||||
expect(storage.setAlarm).toHaveBeenCalledTimes(7)
|
expect(storage.setAlarm).toHaveBeenCalledTimes(7)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ describe('AlarmScheduler', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
jest.spyOn(console, 'log').mockImplementation(noop)
|
jest.spyOn(console, 'log').mockImplementation(noop)
|
||||||
await expect(async () => advanceTime(1000)).rejects.toThrowError(
|
await expect(async () => advanceTime(1000)).rejects.toThrow(
|
||||||
'Some alarms failed to fire, scheduling retry'
|
'Some alarms failed to fire, scheduling retry'
|
||||||
)
|
)
|
||||||
expect(alarms.error).toHaveBeenCalledTimes(1)
|
expect(alarms.error).toHaveBeenCalledTimes(1)
|
||||||
|
|
|
@ -72,9 +72,9 @@
|
||||||
"@microsoft/api-extractor": "^7.35.4",
|
"@microsoft/api-extractor": "^7.35.4",
|
||||||
"@next/eslint-plugin-next": "^13.3.0",
|
"@next/eslint-plugin-next": "^13.3.0",
|
||||||
"@swc/core": "^1.3.55",
|
"@swc/core": "^1.3.55",
|
||||||
"@swc/jest": "^0.2.26",
|
"@swc/jest": "^0.2.34",
|
||||||
"@types/glob": "^8.1.0",
|
"@types/glob": "^8.1.0",
|
||||||
"@types/jest": "^28.1.2",
|
"@types/jest": "^29.5.12",
|
||||||
"@types/node": "~20.11",
|
"@types/node": "~20.11",
|
||||||
"@types/react": "^18.2.47",
|
"@types/react": "^18.2.47",
|
||||||
"@types/react-dom": "^18.2.18",
|
"@types/react-dom": "^18.2.18",
|
||||||
|
@ -91,7 +91,7 @@
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
"fs-extra": "^11.1.0",
|
"fs-extra": "^11.1.0",
|
||||||
"husky": "^8.0.0",
|
"husky": "^8.0.0",
|
||||||
"jest": "^29.7.0",
|
"jest": "30.0.0-alpha.2",
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"lazyrepo": "0.0.0-alpha.27",
|
"lazyrepo": "0.0.0-alpha.27",
|
||||||
"lint-staged": ">=10",
|
"lint-staged": ">=10",
|
||||||
|
|
|
@ -29,11 +29,11 @@ describe('get order between', () => {
|
||||||
expect(generateKeyBetween('zzzzzzzzzzzzzzzzzzzzzzzzzzz', undefined)).toBe(
|
expect(generateKeyBetween('zzzzzzzzzzzzzzzzzzzzzzzzzzz', undefined)).toBe(
|
||||||
'zzzzzzzzzzzzzzzzzzzzzzzzzzzV'
|
'zzzzzzzzzzzzzzzzzzzzzzzzzzzV'
|
||||||
)
|
)
|
||||||
expect(() => generateKeyBetween(undefined, 'A00000000000000000000000000')).toThrowError()
|
expect(() => generateKeyBetween(undefined, 'A00000000000000000000000000')).toThrow()
|
||||||
expect(() => generateKeyBetween('a00', undefined)).toThrowError()
|
expect(() => generateKeyBetween('a00', undefined)).toThrow()
|
||||||
expect(() => generateKeyBetween('a00', 'a1')).toThrowError()
|
expect(() => generateKeyBetween('a00', 'a1')).toThrow()
|
||||||
expect(() => generateKeyBetween('0', '1')).toThrowError()
|
expect(() => generateKeyBetween('0', '1')).toThrow()
|
||||||
expect(() => generateKeyBetween('a1', 'a0')).toThrowError()
|
expect(() => generateKeyBetween('a1', 'a0')).toThrow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ describe('define migrations tests', () => {
|
||||||
// @ts-expect-error first version without current version
|
// @ts-expect-error first version without current version
|
||||||
firstVersion: Versions.Initial,
|
firstVersion: Versions.Initial,
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// no versions
|
// no versions
|
||||||
|
@ -23,7 +23,7 @@ describe('define migrations tests', () => {
|
||||||
// @ts-expect-error first version without current version
|
// @ts-expect-error first version without current version
|
||||||
firstVersion: Versions.February,
|
firstVersion: Versions.February,
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// empty migrators
|
// empty migrators
|
||||||
|
@ -31,7 +31,7 @@ describe('define migrations tests', () => {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
migrators: {},
|
migrators: {},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// no versions!
|
// no versions!
|
||||||
|
@ -44,7 +44,7 @@ describe('define migrations tests', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// wrong current version!
|
// wrong current version!
|
||||||
|
@ -58,7 +58,7 @@ describe('define migrations tests', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
defineMigrations({
|
defineMigrations({
|
||||||
|
@ -76,7 +76,7 @@ describe('define migrations tests', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// can't provide only first version
|
// can't provide only first version
|
||||||
|
@ -86,7 +86,7 @@ describe('define migrations tests', () => {
|
||||||
// @ts-expect-error migrators without current version
|
// @ts-expect-error migrators without current version
|
||||||
migrators: {},
|
migrators: {},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// same version
|
// same version
|
||||||
|
@ -95,7 +95,7 @@ describe('define migrations tests', () => {
|
||||||
currentVersion: Versions.Initial,
|
currentVersion: Versions.Initial,
|
||||||
migrators: {},
|
migrators: {},
|
||||||
})
|
})
|
||||||
}).toThrowError()
|
}).toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// only first version
|
// only first version
|
||||||
|
@ -105,7 +105,7 @@ describe('define migrations tests', () => {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
migrators: {},
|
migrators: {},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// missing only version
|
// missing only version
|
||||||
|
@ -115,7 +115,7 @@ describe('define migrations tests', () => {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
migrators: {},
|
migrators: {},
|
||||||
})
|
})
|
||||||
}).toThrowError()
|
}).toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// only version, explicit start and current
|
// only version, explicit start and current
|
||||||
|
@ -129,7 +129,7 @@ describe('define migrations tests', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}).toThrowError()
|
}).toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// missing later versions
|
// missing later versions
|
||||||
|
@ -139,7 +139,7 @@ describe('define migrations tests', () => {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
migrators: {},
|
migrators: {},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// missing later versions
|
// missing later versions
|
||||||
|
@ -154,7 +154,7 @@ describe('define migrations tests', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// missing earlier versions
|
// missing earlier versions
|
||||||
|
@ -169,7 +169,7 @@ describe('define migrations tests', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// got em all
|
// got em all
|
||||||
|
@ -187,7 +187,7 @@ describe('define migrations tests', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// got em all starting later
|
// got em all starting later
|
||||||
|
@ -205,7 +205,7 @@ describe('define migrations tests', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// first migration should be first version + 1
|
// first migration should be first version + 1
|
||||||
|
@ -224,6 +224,6 @@ describe('define migrations tests', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -912,6 +912,6 @@ describe('snapshots', () => {
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
store2.loadSnapshot(snapshot1)
|
store2.loadSnapshot(snapshot1)
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -112,14 +112,14 @@ describe('Validating initial data', () => {
|
||||||
it('Validates initial data', () => {
|
it('Validates initial data', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
new Store<Book | Author>({ schema, initialData: snapshot, props: {} })
|
new Store<Book | Author>({ schema, initialData: snapshot, props: {} })
|
||||||
}).not.toThrowError()
|
}).not.toThrow()
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
snapshot[0].name = 4
|
snapshot[0].name = 4
|
||||||
|
|
||||||
new Store<Book | Author>({ schema, initialData: snapshot, props: {} })
|
new Store<Book | Author>({ schema, initialData: snapshot, props: {} })
|
||||||
}).toThrowError()
|
}).toThrow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ it('Uses typescript generics', () => {
|
||||||
type: 'arrow',
|
type: 'arrow',
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
}).toThrowError()
|
}).toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Parents shapes to the current page if the parent is not found', () => {
|
it('Parents shapes to the current page if the parent is not found', () => {
|
||||||
|
|
|
@ -16,17 +16,17 @@ describe('Migrations', () => {
|
||||||
const withoutSchema = structuredClone(clipboardContent)
|
const withoutSchema = structuredClone(clipboardContent)
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
delete withoutSchema.schema
|
delete withoutSchema.schema
|
||||||
expect(() => editor.putContentOntoCurrentPage(withoutSchema)).toThrowError()
|
expect(() => editor.putContentOntoCurrentPage(withoutSchema)).toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Does not throw error if content has a schema', () => {
|
it('Does not throw error if content has a schema', () => {
|
||||||
expect(() => editor.putContentOntoCurrentPage(clipboardContent)).not.toThrowError()
|
expect(() => editor.putContentOntoCurrentPage(clipboardContent)).not.toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Throws error if any shape is invalid due to wrong type', () => {
|
it('Throws error if any shape is invalid due to wrong type', () => {
|
||||||
const withInvalidShapeType = structuredClone(clipboardContent)
|
const withInvalidShapeType = structuredClone(clipboardContent)
|
||||||
withInvalidShapeType.shapes[0].type = 'invalid'
|
withInvalidShapeType.shapes[0].type = 'invalid'
|
||||||
expect(() => editor.putContentOntoCurrentPage(withInvalidShapeType)).toThrowError()
|
expect(() => editor.putContentOntoCurrentPage(withInvalidShapeType)).toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
// we temporarily disabled validations
|
// we temporarily disabled validations
|
||||||
|
@ -34,6 +34,6 @@ describe('Migrations', () => {
|
||||||
const withInvalidShapeModel = structuredClone(clipboardContent)
|
const withInvalidShapeModel = structuredClone(clipboardContent)
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
withInvalidShapeModel.shapes[0].x = 'invalid'
|
withInvalidShapeModel.shapes[0].x = 'invalid'
|
||||||
expect(() => editor.putContentOntoCurrentPage(withInvalidShapeModel)).toThrowError()
|
expect(() => editor.putContentOntoCurrentPage(withInvalidShapeModel)).toThrow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -77,7 +77,7 @@ it('Uses typescript generics', () => {
|
||||||
type: 'arrow',
|
type: 'arrow',
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
}).toThrowError()
|
}).toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updates shapes', () => {
|
it('updates shapes', () => {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { debounce } from './debounce'
|
import { debounce } from './debounce'
|
||||||
|
|
||||||
jest.useFakeTimers()
|
jest.useFakeTimers()
|
||||||
|
|
||||||
describe(debounce, () => {
|
describe(debounce, () => {
|
||||||
it('should debounce a function', async () => {
|
it('should debounce a function', async () => {
|
||||||
const fn = jest.fn()
|
const fn = jest.fn()
|
||||||
|
@ -8,13 +9,13 @@ describe(debounce, () => {
|
||||||
debounced()
|
debounced()
|
||||||
debounced()
|
debounced()
|
||||||
debounced()
|
debounced()
|
||||||
expect(fn).not.toBeCalled()
|
expect(fn).not.toHaveBeenCalled()
|
||||||
jest.advanceTimersByTime(200)
|
jest.advanceTimersByTime(200)
|
||||||
expect(fn).toBeCalledTimes(1)
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
jest.advanceTimersByTime(200)
|
jest.advanceTimersByTime(200)
|
||||||
expect(fn).toBeCalledTimes(1)
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
jest.advanceTimersByTime(200)
|
jest.advanceTimersByTime(200)
|
||||||
expect(fn).toBeCalledTimes(1)
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should debounce a function with arguments', async () => {
|
it('should debounce a function with arguments', async () => {
|
||||||
|
@ -23,10 +24,10 @@ describe(debounce, () => {
|
||||||
debounced('a', 'b')
|
debounced('a', 'b')
|
||||||
debounced('a', 'b')
|
debounced('a', 'b')
|
||||||
debounced('a', 'b')
|
debounced('a', 'b')
|
||||||
expect(fn).not.toBeCalled()
|
expect(fn).not.toHaveBeenCalled()
|
||||||
jest.advanceTimersByTime(200)
|
jest.advanceTimersByTime(200)
|
||||||
expect(fn).toBeCalledTimes(1)
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
expect(fn).toBeCalledWith('a', 'b')
|
expect(fn).toHaveBeenCalledWith('a', 'b')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should debounce a function with arguments and return a promise', async () => {
|
it('should debounce a function with arguments and return a promise', async () => {
|
||||||
|
@ -35,9 +36,9 @@ describe(debounce, () => {
|
||||||
const promiseA = debounced('a', 'b')
|
const promiseA = debounced('a', 'b')
|
||||||
const promiseB = debounced('c', 'd')
|
const promiseB = debounced('c', 'd')
|
||||||
const promiseC = debounced('e', 'f')
|
const promiseC = debounced('e', 'f')
|
||||||
expect(fn).not.toBeCalled()
|
expect(fn).not.toHaveBeenCalled()
|
||||||
jest.advanceTimersByTime(200)
|
jest.advanceTimersByTime(200)
|
||||||
expect(fn).toBeCalledTimes(1)
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
const results = await Promise.all([promiseA, promiseB, promiseC])
|
const results = await Promise.all([promiseA, promiseB, promiseC])
|
||||||
|
|
||||||
expect(results).toEqual(['ef', 'ef', 'ef'])
|
expect(results).toEqual(['ef', 'ef', 'ef'])
|
||||||
|
@ -48,19 +49,19 @@ describe(debounce, () => {
|
||||||
const debounced = debounce(fn, 100)
|
const debounced = debounce(fn, 100)
|
||||||
const promiseA = debounced('a', 'b')
|
const promiseA = debounced('a', 'b')
|
||||||
const promiseB = debounced('c', 'd')
|
const promiseB = debounced('c', 'd')
|
||||||
expect(fn).not.toBeCalled()
|
expect(fn).not.toHaveBeenCalled()
|
||||||
jest.advanceTimersByTime(200)
|
jest.advanceTimersByTime(200)
|
||||||
expect(fn).toBeCalledTimes(1)
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
|
|
||||||
expect(await Promise.all([promiseA, promiseB])).toEqual(['cd', 'cd'])
|
expect(await Promise.all([promiseA, promiseB])).toEqual(['cd', 'cd'])
|
||||||
|
|
||||||
const promiseC = debounced('e', 'f')
|
const promiseC = debounced('e', 'f')
|
||||||
const promiseD = debounced('g', 'h')
|
const promiseD = debounced('g', 'h')
|
||||||
expect(fn).toBeCalledTimes(1)
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
|
|
||||||
jest.advanceTimersByTime(200)
|
jest.advanceTimersByTime(200)
|
||||||
|
|
||||||
expect(fn).toBeCalledTimes(2)
|
expect(fn).toHaveBeenCalledTimes(2)
|
||||||
expect(await Promise.all([promiseC, promiseD])).toEqual(['gh', 'gh'])
|
expect(await Promise.all([promiseC, promiseD])).toEqual(['gh', 'gh'])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue