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

Consider a way to support/add equalJSX method #186

Closed
MoOx opened this issue Nov 10, 2015 · 6 comments
Closed

Consider a way to support/add equalJSX method #186

MoOx opened this issue Nov 10, 2015 · 6 comments

Comments

@MoOx
Copy link

MoOx commented Nov 10, 2015

I am currently using tape and I am considering switching to AVA.
There is just one piece missing atm: https://github.com/atabel/tape-jsx-equals
As you can see tape-jsx-equals use extend-tape to extends tape.
Are you open to add support of equalJSX in the core? If not will it be possible to provide a way to easily extends AVA?

@MoOx
Copy link
Author

MoOx commented Nov 10, 2015

Note: this is assertion is doable using https://github.com/algolia/react-element-to-jsx-string

@MoOx
Copy link
Author

MoOx commented Nov 10, 2015

Also please note that another method is really handy when testing react component: includeJSX. This one ignore whitespace differences which can be very handy.

@jamestalmage
Copy link
Contributor

@MoOx The ability to add custom assertions is on the roadmap.

@sindresorhus
Copy link
Member

You can already use any custom assertion. The only minus is that assertion counting doesn't work. We plan to add support for adding custom assertions. See #49.

@MoOx
Copy link
Author

MoOx commented Dec 2, 2015

FYI, here is how I do for now

import "babel-core/register"
import test from "ava"

import React, { Component } from "react"
import { createRenderer } from "react-addons-test-utils"
// import ReactDOMServer from "react-dom/server"
import expect from "expect"
import expectJSX from "expect-jsx"
expect.extend(expectJSX)

import MyComponent from ".."

test("MyComponent default render", (t) => {
  const renderer = createRenderer()

  renderer.render(
    <MyComponent />
  )
  expect(
    renderer.getRenderOutput()
  )
  .toEqualJSX(
    <div />
  )
})

Result

npm run ava

> ~@ ava ~
> ava "web_modules/**/__tests__/*.js"


  ✖ MyComponent default render Expected '<div>\n  <div className="container-navigation-list" />\n</div>' to equal '<div />'

  1 test failed

  1. MyComponent default render
  Error: Expected '<div>\n  <div className="container-navigation-list" />\n</div>' to equal '<div />'
    at Object.assert [as default] (~/node_modules/expect/lib/assert.js:20:9)
    at Expectation.toEqual (~/node_modules/expect/lib/Expectation.js:69:26)
    at Expectation.toEqualJSX (~/node_modules/expect-jsx/index-dist.js:27:93)
    at Test.fn (~/web_modules/Portal/__tests__/index.js:40:56)
    at tryCatcher (~/node_modules/bluebird/js/release/util.js:11:23)
    at Object.gotValue (~/node_modules/bluebird/js/release/reduce.js:145:18)
    at Object.gotAccum (~/node_modules/bluebird/js/release/reduce.js:134:25)
    at Object.tryCatcher (~/node_modules/bluebird/js/release/util.js:11:23)
    at Promise._settlePromiseFromHandler (~/node_modules/bluebird/js/release/promise.js:489:31)
    at Promise._settlePromise (~/node_modules/bluebird/js/release/promise.js:546:18)
    at Promise._settlePromiseCtx (~/node_modules/bluebird/js/release/promise.js:583:10)
    at Async._drainQueue (~/node_modules/bluebird/js/release/async.js:134:12)
    at Async._drainQueues (~/node_modules/bluebird/js/release/async.js:139:10)
    at Immediate.Async.drainQueues [as _onImmediate] (~/node_modules/bluebird/js/release/async.js:16:14)

@novemberborn
Copy link
Member

Let's continue discussion in #446. Any future improvements will benefit from our solution to #25.

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

4 participants