feat(editor): Add toJsonString to string extensions (#13798)

This commit is contained in:
Dana
2025-03-11 10:34:09 +01:00
committed by GitHub
parent 9c040ee5a5
commit 4e93ffda8b
2 changed files with 30 additions and 0 deletions

View File

@@ -313,6 +313,14 @@ describe('Data Transformation Functions', () => {
expect(() => evaluate('={{ "No JSON here".parseJson() }}')).toThrowError('Parsing failed');
});
test('.toJsonString should work on a string', () => {
expect(evaluate('={{ "test".toJsonString() }}')).toEqual(JSON.stringify('test'));
expect(evaluate('={{ "The \\"best\\" colours: red\\nbrown".toJsonString() }}')).toEqual(
JSON.stringify('The "best" colours: red\nbrown'),
);
expect(evaluate('={{ "".toJsonString() }}')).toEqual(JSON.stringify(''));
});
test('.toBoolean should work on a string', () => {
expect(evaluate('={{ "False".toBoolean() }}')).toBe(false);
expect(evaluate('={{ "".toBoolean() }}')).toBe(false);