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

Faulty code does not throw an error #983

Closed
Timyipstudio opened this issue Jul 29, 2016 · 4 comments
Closed

Faulty code does not throw an error #983

Timyipstudio opened this issue Jul 29, 2016 · 4 comments
Labels
bug current functionality does not work as desired

Comments

@Timyipstudio
Copy link

Timyipstudio commented Jul 29, 2016

test("foo update", t => {
    try {
        console.log(foo);
        console.log(bar);

        var foo = 1;
        let bar = 2;
    } catch (e) {
        t.is(e.name, 'ReferenceError')
    }
});

when i run code above. it didn't throw a error

@jfmengels
Copy link
Contributor

I think it's because the test code is compiled by Babel, and the compiled code is not trying to cause ReferenceError to be thrown when a variable declared with let/const is used before its declaration.

Not sure there is anything to be done about this.

(By the way, has there been a discussion to only compile only what is needed based on what is supported in the node version that runs the tests? Couldn't find one)

@sindresorhus
Copy link
Member

Looks like a Babel bug or caveat indeed.

@Timyipstudio Could you maybe try asking about it in the Babel support channels?

Sidenote: If you want to check if something throws, use t.throws() instead.

@sindresorhus
Copy link
Member

@jfmengels Yup: #148

@vadimdemedes vadimdemedes added bug current functionality does not work as desired babel labels Aug 9, 2016
@vadimdemedes vadimdemedes changed the title Why does not this code throw an error Faulty code does not throw an error Aug 9, 2016
@novemberborn
Copy link
Member

I could only find babel/babel#563 on this, and there is some TDZ related code in the block-scoping plugin. So maybe this is a Babel bug or maybe Babel decided it's too hard to fix.

As far as AVA goes, we can do better by not transpiling language features that are supported by the Node.js runtime, which is #148.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug current functionality does not work as desired
Projects
None yet
Development

No branches or pull requests

5 participants