Add some tests to the variable resolver to ensure static JSON is properly evaluated (#9104)

This commit is contained in:
Baptiste Devessier
2024-12-17 17:02:16 +01:00
committed by GitHub
parent d0f7270c28
commit f05a217f62

View File

@ -74,4 +74,40 @@ describe('resolveInput', () => {
expect(resolveInput(input, context)).toEqual(expected);
});
it('does not wrap string variables with double quotes', () => {
expect(
resolveInput('{ {{test}}: 2 }', {
test: 'prop',
}),
).toBe('{ prop: 2 }');
});
it('does not modify static JSON', () => {
expect(resolveInput('{ "a": 2 }', {})).toBe('{ "a": 2 }');
});
it('supports variable as JSON object property name', () => {
expect(
resolveInput('{ "{{test}}": 2 }', {
test: 'prop',
}),
).toBe('{ "prop": 2 }');
});
it('supports variable as JSON number value', () => {
expect(
resolveInput('{ "a": {{test}} }', {
test: 2,
}),
).toBe('{ "a": 2 }');
});
it('supports variable as JSON string value', () => {
expect(
resolveInput('{ "a": "{{test}}" }', {
test: 'str',
}),
).toBe('{ "a": "str" }');
});
});