test: fix deprecated Jest matchers for v30

- Replace toThrowError() with toThrow()
- Replace toBeCalledWith() with toHaveBeenCalledWith()
- Update snapshots
This commit is contained in:
Daniel Kennedy
2026-01-30 09:44:37 -05:00
parent 59d7acc324
commit f94d96c596
14 changed files with 44 additions and 44 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ test('unlinkFile unlinks file', async () => {
})
test('assertDefined throws if undefined', () => {
expect(() => cacheUtils.assertDefined('test', undefined)).toThrowError()
expect(() => cacheUtils.assertDefined('test', undefined)).toThrow()
})
test('assertDefined returns value', () => {
+4 -4
View File
@@ -29,7 +29,7 @@ beforeAll(() => {
test('restore with no path should fail', async () => {
const paths: string[] = []
const key = 'node-test'
await expect(restoreCache(paths, key)).rejects.toThrowError(
await expect(restoreCache(paths, key)).rejects.toThrow(
`Path Validation Error: At least one directory or file path is required`
)
})
@@ -38,7 +38,7 @@ test('restore with too many keys should fail', async () => {
const paths = ['node_modules']
const key = 'node-test'
const restoreKeys = [...Array(20).keys()].map(x => x.toString())
await expect(restoreCache(paths, key, restoreKeys)).rejects.toThrowError(
await expect(restoreCache(paths, key, restoreKeys)).rejects.toThrow(
`Key Validation Error: Keys are limited to a maximum of 10.`
)
})
@@ -46,7 +46,7 @@ test('restore with too many keys should fail', async () => {
test('restore with large key should fail', async () => {
const paths = ['node_modules']
const key = 'foo'.repeat(512) // Over the 512 character limit
await expect(restoreCache(paths, key)).rejects.toThrowError(
await expect(restoreCache(paths, key)).rejects.toThrow(
`Key Validation Error: ${key} cannot be larger than 512 characters.`
)
})
@@ -54,7 +54,7 @@ test('restore with large key should fail', async () => {
test('restore with invalid key should fail', async () => {
const paths = ['node_modules']
const key = 'comma,comma'
await expect(restoreCache(paths, key)).rejects.toThrowError(
await expect(restoreCache(paths, key)).rejects.toThrow(
`Key Validation Error: ${key} cannot contain commas.`
)
})
+4 -4
View File
@@ -44,7 +44,7 @@ afterEach(() => {
test('restore with no path should fail', async () => {
const paths: string[] = []
const key = 'node-test'
await expect(restoreCache(paths, key)).rejects.toThrowError(
await expect(restoreCache(paths, key)).rejects.toThrow(
`Path Validation Error: At least one directory or file path is required`
)
})
@@ -53,7 +53,7 @@ test('restore with too many keys should fail', async () => {
const paths = ['node_modules']
const key = 'node-test'
const restoreKeys = [...Array(20).keys()].map(x => x.toString())
await expect(restoreCache(paths, key, restoreKeys)).rejects.toThrowError(
await expect(restoreCache(paths, key, restoreKeys)).rejects.toThrow(
`Key Validation Error: Keys are limited to a maximum of 10.`
)
})
@@ -61,7 +61,7 @@ test('restore with too many keys should fail', async () => {
test('restore with large key should fail', async () => {
const paths = ['node_modules']
const key = 'foo'.repeat(512) // Over the 512 character limit
await expect(restoreCache(paths, key)).rejects.toThrowError(
await expect(restoreCache(paths, key)).rejects.toThrow(
`Key Validation Error: ${key} cannot be larger than 512 characters.`
)
})
@@ -69,7 +69,7 @@ test('restore with large key should fail', async () => {
test('restore with invalid key should fail', async () => {
const paths = ['node_modules']
const key = 'comma,comma'
await expect(restoreCache(paths, key)).rejects.toThrowError(
await expect(restoreCache(paths, key)).rejects.toThrow(
`Key Validation Error: ${key} cannot contain commas.`
)
})
+2 -2
View File
@@ -40,7 +40,7 @@ beforeAll(() => {
test('save with missing input should fail', async () => {
const paths: string[] = []
const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
await expect(saveCache(paths, primaryKey)).rejects.toThrowError(
await expect(saveCache(paths, primaryKey)).rejects.toThrow(
`Path Validation Error: At least one directory or file path is required`
)
})
@@ -342,7 +342,7 @@ test('save with non existing path should not save cache', async () => {
jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async () => {
return []
})
await expect(saveCache([path], primaryKey)).rejects.toThrowError(
await expect(saveCache([path], primaryKey)).rejects.toThrow(
`Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.`
)
})
+2 -2
View File
@@ -54,7 +54,7 @@ test('save with missing input should fail', async () => {
const paths: string[] = []
const key = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
await expect(saveCache(paths, key)).rejects.toThrowError(
await expect(saveCache(paths, key)).rejects.toThrow(
`Path Validation Error: At least one directory or file path is required`
)
})
@@ -581,7 +581,7 @@ test('save with non existing path should not save cache using v2 saveCache', asy
jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async () => {
return []
})
await expect(saveCache([path], key)).rejects.toThrowError(
await expect(saveCache([path], key)).rejects.toThrow(
`Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.`
)
})