import { expect } from 'chai'; import { silentlyParseJson } from '../../../src/helpers/silently-parse-json'; describe('Parse json', () => { it('parses string to json', () => { const jsonString = '{"property":"value"}'; expect(silentlyParseJson(jsonString)).to.eql({ property: 'value' }); }); it('fails silently and returns string', () => { const invalidJsonString = 'hello'; expect(silentlyParseJson(invalidJsonString)).to.equal('hello'); }); it('fails silently and returns an object', () => { const object = { property : 'value' }; // This complains about type safety as it expects a string not a type // However we still want to test the functionality so... // @ts-ignore expect(silentlyParseJson(object)).to.eql({ property : 'value' }); }); });