-
Notifications
You must be signed in to change notification settings - Fork 141
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
Symbols must be stringified explicitly #301
Conversation
Is there a test you could add for this? |
tests in progress. Also found 3 other places where this bug can manifest:
So there are 4 total instances in all. Two of which use
|
af60601
to
8b2b9c3
Compare
First commit is minimal change to fix the issue (just explicitly stringify the keynames)... Second commit is an "improvement" to make the key names more idiomatic when stringified. (Symbol keys are wrapped in brackets). Not sure it's worth the extra code, though. Maybe something to revisit after the rewrite? I can nuke the second commit if we'd like to just do the minimal fix for now. |
Is this done? |
Yeah, it's ready if you're fine with the slight change to the stringified output of the function names (second commit) |
Hey @jasonkarns, apologies that I just got around to reading this (mea culpa). My feeling is that since I'm still mid-rewrite (😭), I don't want to add any superfluous branching anywhere I can avoid it, so I'd really rather merge this fix in without any changes to the stringy output. Could you update with changes that just make the fix without adding the |
600fbed
to
8b2b9c3
Compare
@searls done. there were already separate commits, so i just removed the latter one from the PR |
src/imitate/create-imitation.js
Outdated
@@ -11,7 +11,7 @@ export default (original, names) => { | |||
return original | |||
} else { | |||
// TODO: this will become src/function/create and include parent reference instead of name joining here | |||
return tdFunction(names.join('') || '(anonymous function)') | |||
return tdFunction(names.map(String).join('') || '(anonymous function)') |
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.
Can you please use _.map
for this? We're using lodash for all of our enumerable methods everywhere else, and there's a tacit (but not explicit) support for ancient browsers / IE etc that won't have Array.prototype.map
defined.
@searls _.map 👍 |
Travis is having some downtime so I'm not going to watch this all day. How about you merge & release yourself (once Travis finishes), using this new guide I just wrote? https://github.com/testdouble/testdouble.js/blob/master/RELEASE.md |
Ugh. Probably gonna rebase to latest master, if that's green... |
Definitely rebase to latest
… On Jan 17, 2018, at 1:19 PM, Jason Karns ***@***.***> wrote:
Ugh. test:example tests are failing, but they also fail at the merge-base with master :(
Probably gonna rebase to latest master, if that's green...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Apparently (nodejs/node#927 (comment)), Symbols cannot be implicitly coerced to string. Template stringification leverages implicit coercion, so we must stringify propKey before sending it to the template. Options for explicitly stringifying: - `String(propKey)` - `String.prototype.toString(propKey)` Differences: ``` > String(undefined) 'undefined' > String.prototype.toString(undefined) '' ``` In this case, `propKey` represents the key for the stubbed function. If the key is `undefined`, it would be implicitly coerced to `"undefined"` as the property key. So `String()` is the explicit converstion we want. Four instances of this issue, each where tdFunction is invoked with a dynamic name.
01eee5c
to
a9ffe0a
Compare
Apparently (nodejs/node#927 (comment)),
Symbols cannot be implicitly coerced to string.
Template stringification leverages implicit coercion, so we must
stringify propKey before sending it to the template.
Options for explicitly stringifying:
String(propKey)
String.prototype.toString(propKey)
Differences:
In this case,
propKey
represents the key for the stubbed function. Ifthe key is
undefined
, it would be implicitly coerced to"undefined"
as the property key. So
String()
is the explicit converstion we want.fixes #300 and perhaps maybe fixes #124 ?