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

Using assertion outside the test context leads to nasty crash without good message #345

Closed
bahmutov opened this issue Dec 14, 2016 · 5 comments
Assignees
Labels
type: unexpected behavior User expected result, but got another

Comments

@bahmutov
Copy link
Contributor

If I use "expect" outside a describe block, Cypress 0.18.1 fails to parse the file and shows "no tests found message". It is very unclear to the user why the tests do not start.

It could also related to the "cy.log" command I have added by using #342
I could not reliably recreate the crash in the self-contained example, but this is the principle

function foo(name) {
  expect(name).to.be.a('string')
}
describe('foo', () => {
  it('works', () => {
    foo('foo')
  })
})

Trying to run this breaks Cypress with message "No tests found in your file:" and the following error stack and object arguments (this shows that this is the "expect" assertion crashing)

screen shot 2016-12-14 at 12 09 35 pm

screen shot 2016-12-14 at 12 09 53 pm

@jennifer-shehane jennifer-shehane added the type: unexpected behavior User expected result, but got another label Dec 15, 2016
@bahmutov
Copy link
Contributor Author

bahmutov commented Jun 2, 2017

Even a "simple" exception is not caught in the spec.js file, causing confusion. For example

// example_spec.js
throw new Error('nope')
describe('Kitchen Sink', function(){ ...

shows

screen shot 2017-06-02 at 11 38 30 am

At least should advise the user to open dev tools? Or open dev tools automatically...

@bahmutov
Copy link
Contributor Author

bahmutov commented Jun 2, 2017

@brian-mann
Copy link
Member

brian-mann commented Jun 2, 2017

This is simply an uncaught global exception (which we are not correctly catching) from the spec file. We'll catch errors obviously from within a test but not outside of it.

There's a difference between parse errors and runtime errors. Runtime errors simply lead Cypress to not find any valid tests (since the code bails early) - whereas parse / bundle errors are caught prior to sending down the spec files and can be displayed.

The solution here is simple - catch global uncaught spec errors so we can notify the user there's something wrong with their code.

We already catch global uncaught errors from the application under test, so that same code can be repurposed to catch spec errors.

@bahmutov
Copy link
Contributor Author

bahmutov commented Jun 2, 2017

agree this is the best long term solution. Double points because it solves problem a new user might have (which are higher priority in my mind)

@brian-mann
Copy link
Member

The code for this is done, but this has yet to be released. We'll update the issue and reference the changelog when it's released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: unexpected behavior User expected result, but got another
Projects
None yet
Development

No branches or pull requests

4 participants