-
-
Notifications
You must be signed in to change notification settings - Fork 697
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
Error on strict mode #578
Comments
Thanks for the issue @Tresdin. How are you running these tests? Through Mocha? Through Karma? Are you using CommonJS style |
I'm using
Yes. I am.
No. This code is run on
I run node globally on strict mode (via |
There's your problem! Remove that flag and things will work fine! Not every module you use will implement strict code (for example, Chai does not!). You'd be better off declaring I'm going to close this because we rely on non-strict features (which are still compliant to the JS spec, just not the "strict" part of the spec). It's unlikely we'll change this any time soon, and only errors through edge cases (such as enforcing strict mode on all of your modules, or using babel, etc). |
@keithamus Bad news, indeed. I think you should seriously consider this issue as a critical bug. |
@Tresdin I'm curious; why should chai work in strict mode? "Strict Mode" is an opt in part of JavaScript and as such is not a requirement for engines (or libraries) to implement. Some engines can enforce strict mode (e.g. via Just FYI, the only "non-strict mode" feature (which is a little bit of a misnomer, because it's really a "JavaScript feature which throws an Error in Strict Mode") we use is I suppose if you could find a way around using |
Same reasons why any other piece of Javascript code should work in strict mode.
According to MDN:
So in brief, you will end up writting better, cleaner and even faster code in strict mode. About the solution, I'm not sure what is the difference between
and
since |
Also es modules implicitly add 'use strict'. |
Strict mode is only opt-in because it would wreak havoc on the web to make it suddenly mandatory. Not because its behavior is unimportant. |
I'd like to quickly reiterate:
|
@keithamus what about the solution @Tresdin mentioned? flag(this, 'ssfi', stack || Assertion) Is there something wrong with this? A quick test shows me that it removes the internal function calls from the shown stack trace. I use |
@bezformy I don't know if that solution will be ideal or not - the ssfi part of the codebase is the one I (personally) have the least confidence with. It could indeed be sufficient, as most assertions go through the If you'd like to make a PR for that implementation, please do so. But also if you could add some tests to show that it does work the same as the old behaviour so we can be sure. That'd be awesome 😄. |
@keithamus I think you're overthinking the problem. The only test that you need to write for the change is something similar to this code.
Why should you bother any other code if |
@Tresdin |
You mean
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller There must be some kind of misunderstanding here, because
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee |
Ahh wow, my bad. I suppose I suppose the |
@keithamus I checked the code to see what is tested and what isn't, and I found that this does what you are asking for: Line 55 in 5608a0b
It basically checks if any internal function calls are included in the stack trace or not. Is there anything else that needs to be checked? |
@bezformy good find! That should actually be enough. In that case I welcome a change of just the one line, no extra tests will be needed. Perhaps, though, as part of this change, each file should be given the |
I checked a few things and I think it might be best if the |
Hey @bezformy, thanks for your contribution, the link you've just posted is extremely interesting 😄 Well, so let me summarize this and simplify the question we've came to here. In a nutshell, the error described on the post you linked is due to getting a
The only way this could cause a bug would be if someone used EDIT: I clearly over-thought this so I edited this to include only the correct and useful part. |
Hey @lucasfcosta, I'm not sure I understand this. What is exactly the final decision then? I think the flag(this, 'ssfi', stack || Assertion) The only thing I wouldn't include is the |
@bezformy Ah, I see, I totally agree with you and I think your solution to this is excellent, thanks for explaining. Anyway, there's no final decision here, I'd like to hear everyone's opinion on what they think is better 😄. |
I would add the strict pragma. Whereas the upsides are very practical, the downsides are only hypothetical. And if Chai's philosophy is we shouldn't activate strict mode because it might bite somebody, well, that means using ES modules is also out of the question. The only future-proof approach here is to add it. |
Long term we'll be splitting out most of the code here into separate modules, at which point they'll all be tidied up and very likely have the Having said that, it's not something we need to rush into and it seems to be holding up the actual fix to this. So I suggest this becomes the following:
|
I got this error with the code
expect(value).to.be.null
that run on strict mode.P/s. I'm using
[email protected]
installed vianpm install chai
.The text was updated successfully, but these errors were encountered: