Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 }');
});
Comment on lines +78 to +84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The whitespace in the expected string '{ prop: 2 }' may be implementation-dependent. Consider testing the parsed JSON object instead of the string representation.


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" }');
});
});
Loading