Testing Array Index Wrapping Utilities in Insomnia
This test suite validates the wrapToIndex utility function in Insomnia’s UI components. It ensures proper index wrapping behavior for array-like operations and handles edge cases for circular navigation implementations.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
kong/insomnia
packages/insomnia/src/ui/components/modals/__tests__/utils.test.tsx
import { describe, expect, it } from 'vitest';
import { wrapToIndex } from '../utils';
describe('wrapToIndex', () => {
it.each([
{ index: 0, maxCount: 4, result: 0 },
{ index: 1, maxCount: 4, result: 1 },
{ index: 3, maxCount: 3, result: 0 },
{ index: -1, maxCount: 3, result: 2 },
{ index: -3, maxCount: 3, result: 0 },
])('%p', ({ index, maxCount, result }) => {
expect(wrapToIndex(index, maxCount)).toBe(result);
});
it('throws when max is negative', () => {
const index = 1;
const maxCount = -1;
const execute = () => wrapToIndex(index, maxCount);
expect(execute).toThrow();
});
});