mirror of
https://github.com/tabler/tabler.git
synced 2026-08-29 13:21:29 +04:00
Enable astro/tsconfigs/strictest in the preview package (#2834)
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { requireIndex } from './array'
|
||||
|
||||
describe('requireIndex', () => {
|
||||
it('returns the entry at the given index', () => {
|
||||
expect(requireIndex(['a', 'b', 'c'], 1)).toBe('b')
|
||||
})
|
||||
|
||||
it('throws when the index is out of bounds', () => {
|
||||
expect(() => requireIndex(['a'], 5)).toThrow('Expected an entry at index 5')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,11 @@
|
||||
// Indexes into demo-data arrays (people.json, photos.json, …) that pages trust to have
|
||||
// an entry at a given position. Throws instead of silently rendering `undefined` if that
|
||||
// assumption is ever violated (e.g. a seed file shrinks).
|
||||
|
||||
export function requireIndex<T>(array: readonly T[], index: number): T {
|
||||
const item = array[index]
|
||||
if (item === undefined) {
|
||||
throw new Error(`Expected an entry at index ${index}, got undefined (array has ${array.length} entries)`)
|
||||
}
|
||||
return item
|
||||
}
|
||||
Reference in New Issue
Block a user