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

instanceOf(Array) assertion fails unexpectedly #2913

Closed
json2d opened this issue Dec 7, 2018 · 2 comments
Closed

instanceOf(Array) assertion fails unexpectedly #2913

json2d opened this issue Dec 7, 2018 · 2 comments

Comments

@json2d
Copy link

json2d commented Dec 7, 2018

Current behavior:

Working off of one of the official examples:
https://github.com/cypress-io/cypress-example-api-testing/blob/master/cypress/integration/example_spec.js#L52-L56

if I replace this section with:

  it('loads 2 items', () => {
    cy.request('/todos')
      .its('body')
      .should('be.instanceOf',Array)
  })

this yields this failure:
AssertionError: expected [ Array(2) ] to be an instance of Array

Desired behavior:

Should pass since it indeed it is an Array

Steps to reproduce: (app code and test code)

  1. Clone the project https://github.com/cypress-io/cypress-example-api-testing
  2. Replace https://github.com/cypress-io/cypress-example-api-testing/blob/master/cypress/integration/example_spec.js#L52-L56 with snippet above
  3. Run npm i, npm start, and npm run cy:open
  4. Run example_spec.js test from Cypress ui

Versions

cypress: 3.0.1
os: Windows 10
browser: Chrome 70

@json2d
Copy link
Author

json2d commented Dec 7, 2018

According to chai docs:

Due to limitations in ES5, .instanceof may not always work as expected when using a transpiler such as Babel or TypeScript. In particular, it may produce unexpected results when subclassing built-in object such as Array, Error, and Map. See your transpiler’s docs for details:

Would this be the cause?

@json2d
Copy link
Author

json2d commented Dec 9, 2018

.should('be.an', 'array') works just fine

would still be nice though to have this mentioned somewhere in docs

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

1 participant