mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(core): amend typing for jsonParse() options (#4423)
* 📘 Amend typing for `jsonParse()` options * ✏️ Update rule message and description * 🔀 Cherrypick Adi's work * 🐛 Account for falsy fallback values * ♻️ Use `else if` * ⚡ Add explicit error message as type * ⚡ Consolidate utils tests * ♻️ Use optional chaining * 🔥 Remove patchy type error Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
51
packages/workflow/test/utils.test.ts
Normal file
51
packages/workflow/test/utils.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { jsonParse, deepCopy } from '../src/utils';
|
||||
|
||||
describe('jsonParse', () => {
|
||||
it('parses JSON', () => {
|
||||
expect(jsonParse('[1, 2, 3]')).toEqual([1, 2, 3]);
|
||||
expect(jsonParse('{ "a": 1 }')).toEqual({ a: 1 });
|
||||
});
|
||||
|
||||
it('optionally throws `errorMessage', () => {
|
||||
expect(() => {
|
||||
jsonParse('', { errorMessage: 'Invalid JSON' });
|
||||
}).toThrow('Invalid JSON');
|
||||
});
|
||||
|
||||
it('optionally returns a `fallbackValue`', () => {
|
||||
expect(jsonParse('', { fallbackValue: { foo: 'bar' } })).toEqual({ foo: 'bar' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('deepCopy', () => {
|
||||
it('should deep copy an object', () => {
|
||||
const object = {
|
||||
deep: {
|
||||
props: {
|
||||
list: [{ a: 1 }, { b: 2 }, { c: 3 }],
|
||||
},
|
||||
arr: [1, 2, 3],
|
||||
},
|
||||
arr: [
|
||||
{
|
||||
prop: {
|
||||
list: ['a', 'b', 'c'],
|
||||
},
|
||||
},
|
||||
],
|
||||
func: () => {},
|
||||
date: new Date(),
|
||||
undef: undefined,
|
||||
nil: null,
|
||||
bool: true,
|
||||
num: 1,
|
||||
};
|
||||
const copy = deepCopy(object);
|
||||
expect(copy).toEqual(object);
|
||||
expect(copy).not.toBe(object);
|
||||
expect(copy.arr).toEqual(object.arr);
|
||||
expect(copy.arr).not.toBe(object.arr);
|
||||
expect(copy.deep.props).toEqual(object.deep.props);
|
||||
expect(copy.deep.props).not.toBe(object.deep.props);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user