-
Notifications
You must be signed in to change notification settings - Fork 117
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
JSX diff #37
Comments
Expect just earned an API to allow for extensions... this seems like something that can be done as a separate npm package. Why don't you give it a shot? I expect it's something you can do as |
You can start like this: expect.extend({
toEqualJSX(jsx) {
// this.actual is the thing that was passed to expect()
}
})
expect(<div>hello</div>).toEqualJSX(<div>hello</div>) |
So I did:
It was cool, hope this will be usable for a lot of other people. Since I have been testing with react shallow renderer, comparing using toEqualJSX is a joy. We will write a blog post soon about all this. @mjackson what do you think? |
export default function toEqualJSX(ReactElement) {
return expect(
reactElementToJSXString(this.actual)
).toEqual(
reactElementToJSXString(ReactElement)
);
} I like it. |
This looks great! Let's add something to the README about extensions that people are building. One small nitpick is that people who aren't using ES6 will have to do: var toEqualJSX = require('expect-to-equal-jsx');
expect.extend({
toEqualJSX: toEqualJSX
}); It would be nice instead if your module just exported the object to pass directly to expect.extend(require('expect-to-equal-jsx')); |
👍 |
@mjackson Yes will do, then will open a PR here and we can close this issue then :) |
👍 |
BREAKING CHANGE: you now have to use the package like this: ```js import expectJSX from 'expect-jsx'; expect.extend(expectJSX); ``` fixes #2 fixes #4 fixes #5 ref mjackson/expect#37 (comment) fixes #6
Hi, I am using https://facebook.github.io/react/docs/test-utils.html#shallow-rendering and wondering how we could automatically have expect() show a nice diff when JSX passed?
I am willing to do the development (maybe in another module?) but would like some insight of you. There's already a jasmine project doing it, I find it really nice: https://www.npmjs.com/package/jasmine-react-diff
Let me know how I can help
The text was updated successfully, but these errors were encountered: