{"id":13680363,"url":"https://github.com/algolia/expect-jsx","last_synced_at":"2025-04-13T18:36:24.504Z","repository":{"id":1765055,"uuid":"44347457","full_name":"algolia/expect-jsx","owner":"algolia","description":"✅ toEqualJSX for expect assertion library","archived":false,"fork":false,"pushed_at":"2025-01-13T06:40:12.000Z","size":835,"stargazers_count":409,"open_issues_count":52,"forks_count":17,"subscribers_count":65,"default_branch":"master","last_synced_at":"2025-03-14T05:02:32.649Z","etag":null,"topics":["expect","jest","jsx","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/algolia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-15T21:46:48.000Z","updated_at":"2025-01-04T03:14:02.000Z","dependencies_parsed_at":"2024-01-13T09:36:44.118Z","dependency_job_id":"e4e29187-e9fb-43eb-80a2-345e57907a6e","html_url":"https://github.com/algolia/expect-jsx","commit_stats":{"total_commits":204,"total_committers":15,"mean_commits":13.6,"dds":0.4852941176470589,"last_synced_commit":"a5541851a6a8dc17d98110f175c2902a71eeed12"},"previous_names":["algolia/expect-to-equal-jsx"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fexpect-jsx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fexpect-jsx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fexpect-jsx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fexpect-jsx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/algolia","download_url":"https://codeload.github.com/algolia/expect-jsx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248761670,"owners_count":21157597,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["expect","jest","jsx","react"],"created_at":"2024-08-02T13:01:16.350Z","updated_at":"2025-04-13T18:36:24.480Z","avatar_url":"https://github.com/algolia.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Libraries \u0026 Tools"],"sub_categories":[],"readme":"**Note from maintainers** Since Jest supports [snapshot testing](https://facebook.github.io/jest/docs/en/snapshot-testing.html), we recommend you to use that instead of `expect-jsx`.\n\n`expect-jsx` is no more compatible with recent Jest versions (22), it can be made compatible so feel free to open a PR if so.\n\n# expect-jsx\n\n[![Version][version-svg]][package-url] [![Build Status][travis-svg]][travis-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url]\n\n[travis-svg]: https://img.shields.io/travis/algolia/expect-jsx/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/algolia/expect-jsx\n[license-image]: http://img.shields.io/badge/license-MIT-green.svg?style=flat-square\n[license-url]: LICENSE\n[downloads-image]: https://img.shields.io/npm/dm/expect-jsx.svg?style=flat-square\n[downloads-url]: http://npm-stat.com/charts.html?package=expect-jsx\n[version-svg]: https://img.shields.io/npm/v/expect-jsx.svg?style=flat-square\n[package-url]: https://npmjs.org/package/expect-jsx\n[screenshot]: ./screenshot.png\n\ntoEqualJSX for [mjackson/expect](https://github.com/mjackson/expect).\n\nIt uses [algolia/react-element-to-jsx-string](https://github.com/algolia/react-element-to-jsx-string) in the background to turn React elements into formatted strings.\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*\n\n- [Setup](#setup)\n- [API](#api)\n- [Usage](#usage)\n- [A note about functions](#a-note-about-functions)\n- [Environment requirements](#environment-requirements)\n- [Test](#test)\n- [Build](#build)\n- [Release](#release)\n- [Similar projects](#similar-projects)\n- [Thanks](#thanks)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Setup\n\nYou will most probably use this plugin as a development dependency.\n\n```sh\nyarn add expect-jsx --dev\n```\n\n## API\n\n- expect(ReactComponent|JSX).toEqualJSX(ReactComponent|JSX)\n- expect(ReactComponent|JSX).toNotEqualJSX(ReactComponent|JSX)\n- expect(ReactComponent|JSX).toIncludeJSX(ReactComponent|JSX)\n- expect(ReactComponent|JSX).toNotIncludeJSX(ReactComponent|JSX)\n\n## Usage\n\nHere's an example using [mochajs/mocha](https://github.com/mochajs/mocha).\n\n```js\nimport React from 'react';\nimport expect from 'expect';\nimport expectJSX from 'expect-jsx';\n\nexpect.extend(expectJSX);\n\nclass TestComponent extends React.Component {}\n\ndescribe('expect-jsx', () =\u003e {\n  it('works', () =\u003e {\n    expect(\u003cdiv /\u003e).toEqualJSX(\u003cdiv /\u003e);\n    // ok\n\n    expect(\u003cdiv a=\"1\" b=\"2\" /\u003e).toEqualJSX(\u003cdiv /\u003e);\n    // Error: Expected '\u003cdiv\\n  a=\"1\"\\n  b=\"2\"\\n/\u003e' to equal '\u003cdiv /\u003e'\n\n    expect(\u003cspan /\u003e).toNotEqualJSX(\u003cdiv/\u003e);\n    // ok\n\n    expect(\u003cdiv\u003e\u003cTestComponent /\u003e\u003c/div\u003e).toIncludeJSX(\u003cTestComponent /\u003e);\n    // ok\n  });\n});\n```\n\nIt looks like this when ran:\n\n![Screenshot when using mocha][screenshot]\n\n## A note about functions\n\n`toEqualJSX` will not check for function references, it only checks that if a `function` was\nexpected somewhere, there's also a function in the actual data.\n\nIt's your responsibility to then unit test those functions.\n\n## Environment requirements\n\nThe environment you use to use `react-element-to-jsx-string` should have [ES2015](https://babeljs.io/learn-es2015/) support.\n\nUse the [Babel polyfill](https://babeljs.io/docs/usage/polyfill/) or any other method that will make you\nenvironment behave like an ES2015 environment.\n\n## Test\n\n```sh\nyarn test\nyarn test:watch\n```\n\n## Build\n\n```sh\nyarn build\nyarn build:watch\n```\n\n## Release\n\nDecide if this is a `patch`, `minor` or `major` release, look at http://semver.org/\n\n```sh\nyarn release [major|minor|patch|x.x.x]\n```\n\n## Similar projects\n\nThere are multiple similar projects for other assertions libraries, all based on\n[algolia/react-element-to-jsx-string](https://github.com/algolia/react-element-to-jsx-string).\nFor instance:\n\n* [chai-equal-jsx](https://www.npmjs.com/package/chai-equal-jsx), assertions for chai:\n  `expect(\u003cdiv /\u003e).to.equalJSX(\u003cdiv /\u003e);`\n* [chai-jsx](https://www.npmjs.com/package/chai-jsx), assertions for chai:\n  `expect(\u003cdiv /\u003e).jsx.to.equal(\u003cdiv /\u003e);`\n* [jsx-chai](https://github.com/bkonkle/jsx-chai), assertions for chai:\n  `expect(\u003cdiv /\u003e).to.deep.equal(\u003cdiv /\u003e);`\n* [tape-jsx-equals](https://www.npmjs.com/package/tape-jsx-equals), assertions for tape:\n  `t.jsxEquals(\u003cdiv /\u003e, \u003cdiv /\u003e);`\n* [jasmine-expect-jsx](https://www.npmjs.com/package/jasmine-expect-jsx), assertions for jasmine:\n  `expect(\u003cdiv /\u003e).toEqualJSX(\u003cdiv /\u003e);`\n\n## Thanks\n\nTo the people pointing me in the right directions like:\n- https://github.com/facebook/react/issues/4835\n- https://github.com/mjackson/expect/issues/37\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgolia%2Fexpect-jsx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falgolia%2Fexpect-jsx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgolia%2Fexpect-jsx/lists"}