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

Support symbols in array arg to createSpyObj() and expect().toHaveBeenCalled() etc #1250

Closed
nbransby opened this issue Jan 3, 2017 · 3 comments

Comments

@nbransby
Copy link

nbransby commented Jan 3, 2017

 - What version are you using? 2.5.2

Symbols don't appear to work in these methods, I get the error:

TypeError: Cannot convert a Symbol value to a string
@slackersoft
Copy link
Member

This doesn't seem like something that add a whole lot of value to Jasmine, especially since we can't simply .toString() it to get the correct equivalent string. Additionally, since there isn't an Internet Explorer version that supports Symbols, it would require a bunch of effort to make sure this code doesn't break in those browsers.

I'm going to close this. Thanks for using Jasmine!

@nbransby
Copy link
Author

nbransby commented Feb 12, 2017

Do you mean for logging? You can toString() a symbol. I have no words for no support in IE being a reason not to implement! Maybe an example would help clarify, here is what I have to do to workround this issue:

        const handler = jasmine.createSpyObj('response', ['onText'])
        functionUnderTest({
                [onText]: (text) => handler.onText(text)
        })
        expect(handler.onText).toHaveBeenCalled();

with the onText var being the symbol - what I would like to write instead:

        const handler = jasmine.createSpyObj('response', [onText])
        functionUnderTest(handler)
        expect(handler[onText]).toHaveBeenCalled();

Maybe you would accept a PR for this?

@slackersoft
Copy link
Member

Unfortunately, the toString() on a Symbol doesn't return the text of the symbol.

> Symbol('foo').toString()
"Symbol(foo)"

This means that the Jasmine code would need to specifically know about Symbols in order to get the value foo that you want out of it.

Jasmine currently maintains support for IE 8 and up, while this doesn't mean we don't want any code that can't be run on IE8, it does mean we need to be careful about supporting features that completely don't exist in certain browsers.

This is not currently something that we want to merge in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants