-
Notifications
You must be signed in to change notification settings - Fork 475
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
feature: add query as object constructor and tests #367
feature: add query as object constructor and tests #367
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great! do you want to extend the exception for the fragment as well?
src/URI.js
Outdated
if (hasOwn.call(this._parts, key)) { | ||
this._parts[key] = src[key]; | ||
} | ||
} | ||
this.query(src['query']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably only be executed if src.query
is actually defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely! will update.
edit: should it be a test that fail in this case? all tests were passing anyway.
src/URI.js
Outdated
for (key in src) { | ||
if (key === 'query') { | ||
hasQueryPart = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait a second, this can be true even if src['query']
is undefined, isnt it?
maybe I should have changed it to
if (key === 'query' && src[key] !== undefined) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can keep the if (key === 'query') { continue; }
part and add if (src.query) { this.query(src.query, false); }
. you only need to execute .query() if there actually is a value (other than null, undefined, empty-string)
… value as a query
About fragments: I think we should open its own issue and solve it in its own PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the tests could use equal() and deepEqual() to provide better messages in case of failure
test/test.js
Outdated
}); | ||
ok(u instanceof URI, 'instanceof URI'); | ||
ok(typeof u.query() === 'string', 'query is string'); | ||
ok(u.query() === 'foo=bar&bar=foo', 'query has right value'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
equal(u.query(), 'foo=bar&bar=foo', 'query() value');
test/test.js
Outdated
ok(typeof u.query() === 'string', 'query is string'); | ||
ok(u.query() === 'foo=bar&bar=foo', 'query has right value'); | ||
ok(u.search() === '?foo=bar&bar=foo', 'search has right value'); | ||
ok(typeof u.query(true) === 'object', 'query map is object'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deepEqual(u.query(true), { foo: 'bar', bar: 'foo' }, 'query(true) value');
fine by me :) |
thank you! |
You're welcome, looking forward to this being released! 👍 |
Attempt to resolve #366