Testing Import Conversion and Key Name Validation in Insomnia
This test suite validates the import functionality and key name validation in the Insomnia project. It focuses on testing error handling during file imports and the behavior of the dotInKeyNameInvariant function for detecting invalid key names.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
kong/insomnia
packages/insomnia/src/utils/importers/__tests__/convert.test.ts
import { fail } from 'assert';
import { describe, expect, it } from 'vitest';
import { convert, dotInKeyNameInvariant } from '../convert';
describe('Import errors', () => {
it('fail to find importer', async () => {
try {
await convert('foo');
fail('Should have thrown error');
} catch (err) {
expect(err.message).toBe('No importers found for file');
}
});
});
describe('test dotInKeyNameInvariant', () => {
[
{
input: {
'.hehe': 'haha',
},
noError: false,
},
{
input: {
'.': '',
'arr': [''],
},
noError: false,
},
{
input: [
'',
1,
],
noError: true,
},
].forEach(testCase => {
it(`check: ${testCase.input}`, () => {
let e: Error | undefined = undefined;
try {
dotInKeyNameInvariant(testCase.input);
} catch (ex) {
e = ex;
}
expect(e === undefined).toBe(testCase.noError);
});
});
});