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

Bug Fix #36

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const parseString = (() => {
}

if (typeof value === 'function') {
return value();
value = value();
}

if (typeof value === 'object') {
Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ describe('json-template', () => {
assert.deepEqual(template.parameters, [{ key: 'userCard' }]);
assert.deepEqual(template({ userCard: () => ({ id: 1, user: "John" }) }), [{ id: 1, user: "John" }]);
});

it('should compute template with function with multiple inner parameters', () => {
const template = parse(JSON.stringify({ username: "{{username}}", password: "{{password}}" }));
assert.deepEqual(template.parameters, [{ key: 'username' }, { key: 'password' }]);
assert.equal(template({ username: () => ("John"), password: () => ("John") }), '{"username":"John","password":"John"}');
Copy link
Member

Choose a reason for hiding this comment

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

@pranavwani I'm confused as to why template() is returning a string here. I would have expected it to return the object itself. Also, this test could be improved by using a different value for password.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, actually trying to passing JSON string to the template parser. It's similar to string with multiple arguments.

I think comment should be appropriate.

});
});

// This section tests that arbitrary types may be present
Expand Down