* test: add web helpers tests * fix: coverage report * test: add more tests * test: add more generated tests * chore: add more tests * test: add more tests
22 lines
770 B
TypeScript
22 lines
770 B
TypeScript
// json.test.ts
|
|
import { safeJsonParse } from './json';
|
|
|
|
describe('safeJsonParse', () => {
|
|
it('should correctly parse a valid JSON string', () => {
|
|
const jsonString = '{"name": "John", "age": 30}';
|
|
const result = safeJsonParse<{ name: string; age: number }>(jsonString);
|
|
expect(result).toEqual({ name: 'John', age: 30 });
|
|
});
|
|
|
|
it('should return undefined for an invalid JSON string', () => {
|
|
const jsonString = '{"name": "John", "age": 30';
|
|
const result = safeJsonParse<{ name: string; age: number }>(jsonString);
|
|
expect(result).toBeUndefined();
|
|
});
|
|
|
|
it('should return undefined for an empty string', () => {
|
|
const jsonString = '';
|
|
const result = safeJsonParse<unknown>(jsonString);
|
|
expect(result).toBeUndefined();
|
|
});
|
|
}); |