{"id":15647812,"url":"https://github.com/psychollama/expect-enzyme","last_synced_at":"2025-04-30T11:33:59.869Z","repository":{"id":71453311,"uuid":"83629572","full_name":"PsychoLlama/expect-enzyme","owner":"PsychoLlama","description":"Enzyme assertions for mjackson's Expect library","archived":false,"fork":false,"pushed_at":"2018-01-27T21:23:06.000Z","size":290,"stargazers_count":42,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T01:38:03.622Z","etag":null,"topics":["assert","enzyme","expect","test"],"latest_commit_sha":null,"homepage":null,"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/PsychoLlama.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2017-03-02T03:21:50.000Z","updated_at":"2024-07-29T23:50:58.000Z","dependencies_parsed_at":"2023-04-17T20:33:09.908Z","dependency_job_id":null,"html_url":"https://github.com/PsychoLlama/expect-enzyme","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PsychoLlama%2Fexpect-enzyme","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PsychoLlama%2Fexpect-enzyme/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PsychoLlama%2Fexpect-enzyme/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PsychoLlama%2Fexpect-enzyme/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PsychoLlama","download_url":"https://codeload.github.com/PsychoLlama/expect-enzyme/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251691769,"owners_count":21628388,"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":["assert","enzyme","expect","test"],"created_at":"2024-10-03T12:21:14.860Z","updated_at":"2025-04-30T11:33:59.839Z","avatar_url":"https://github.com/PsychoLlama.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# expect-enzyme\n*Super-powered enzyme assertions*\n\n[![Travis branch](https://img.shields.io/travis/PsychoLlama/expect-enzyme/master.svg?style=flat-square)](https://travis-ci.org/PsychoLlama/expect-enzyme)\n[![npm downloads](https://img.shields.io/npm/dt/expect-enzyme.svg?style=flat-square)](https://www.npmjs.com/package/expect-enzyme)\n[![npm versions](https://img.shields.io/npm/v/expect-enzyme.svg?style=flat-square)](https://www.npmjs.com/package/expect-enzyme)\n\n## Why you need this\nThe [expect](https://github.com/mjackson/expect) library by [mjackson](https://github.com/mjackson) is super great. I'm not gonna try to convince you of that. Try it for yourself and experience the magic of improved error messages.\n\nWhile `expect` excels in delivering quality errors messages, it has no idea what enzyme is.\n\nIf you're writing React tests with expect, you've probably seen this madness:\n\n```js\n// Assert that \"MyComponent\" exists.\nexpect(element.find('MyComponent').exists()).toBe(true)\n\n// Assert \"Counter\" was given the number 6.\nexpect(element.find('Counter').prop('count')).toBe(6)\n```\n\nThat's cool and all, but what kind of error messages do you get?\n\n```plain\nError: Expected false to be true\n\nError: Expected 0 to be 6\n```\n\nI think we can improve.\n\n## Why it's awesome\nThis library teaches expect how to enzyme. It adds detection to built-ins, and extends it with new enzyme-specific assertions.\n\nFor example:\n\n```js\nexpect(element).toBeA('video')\n// Error: Expected div to be a video\n\nexpect(leaderboard).toContain('HighScore')\n// Error: Expected element to contain \"HighScore\"\n\nexpect(clickCounter).toHaveState({ clicks: 1 })\n// Error: Expected state \"clicks\" to equal 1\n```\n\nYou get the idea.\n\n## Installation\n\n```sh\n$ npm install --save-dev expect@1.x.x expect-enzyme\n```\n\n\u003e **WARNING:** `expect` merged with the [Jest](https://github.com/facebook/jest) project and underwent massive changes, leaving this library incompatible. Using anything later than `v1` may literally explode the universe.\u003cbr /\u003e\nIMHO, it was a good change. Jest is an incredible test framework. They'll do well by `expect`.\n\nIf node starts yelling about missing packages, you might wanna install these too, then skim [the enzyme install docs](http://airbnb.io/enzyme/docs/installation/index.html).\n\n```sh\n# Setup is weird. This should help.\n$ npm install --save-dev enzyme react react-dom react-test-renderer enzyme-adapter-react-16\n```\n\n### Extending\n\n```js\nimport expect from 'expect'\nimport enzymify from 'expect-enzyme'\n\n// Infects the kernel with a crippling rootkit.\n// Just kidding.\nexpect.extend(enzymify())\n```\n\n## API\n\n- [Augmented](#augmented)\n- [Extensions](#extensions)\n\n### Augmented\nThese are the expect methods that understand enzyme with this plugin:\n\n- [.toBeA](#tobeatype)\n- [.toBeAn](#tobeatype)\n- [.toNotBeA](#tonotbeatype)\n- [.toNotBeAn](#tonotbeatype)\n- [.toExist](#toexist)\n- [.toNotExist](#tonotexist)\n- [.toContain](#tocontainselector)\n- [.toNotContain](#tonotcontainselector)\n\n\n#### `.toBeA(type)`\nAsserts a component is the given type.\n\n```js\n// Can use a string...\nexpect(element).toBeA('video')\n\n// Or a component type.\nexpect(element).toBeA(ProfilePage)\n```\n\n##### Error\n\n```plain\nError: Expected div to be a video\n```\n\n\u003e Aliases: `.toBeAn()`\n\n#### `.toNotBeA(type)`\nAsserts a component is not the given type.\n\n```js\n// Once again, it accepts a string...\nexpect(element).toNotBeA('nav')\n\n// Or a component type.\nexpect(element).toNotBeA(DropDown)\n```\n\n##### Error\n\n```plain\nError: Expected nav to not be a nav\nError: Expected DropDown to not be a DropDown\n```\n\n\u003e Aliases: `.toNotBeAn()`\n\n#### `.toExist()`\nAsserts an element exists.\n\n```js\nexpect(element).toExist()\n```\n\n##### Error\n\n```plain\nError: Expected element to exist\n```\n\n#### `.toNotExist()`\nAsserts an element does not exist.\n\n\u003e **Note:** using [`.toNotContain`](#tonotcontainselector) often produces better error messages.\n\n```js\n// This shouldn't contain an ErrorMessage component.\nexpect(element.find('ErrorMessage')).toNotExist()\n```\n\n##### Error\n\n```plain\nError: Expected element to not exist\n```\n\n#### `.toContain(selector)`\nAsserts the component does contain the given selector.\n\n```js\n// This blog post should have a byline.\nexpect(blogPost).toContain('article')\n\n// Works with components, too.\nexpect(blogPost).toContain(AuthorByline)\n\n// And attribute selectors. But please don't.\nexpect(blogPost).toContain({ commentsEnabled: true })\n```\n\n##### Error\n\n```plain\nError: Expected element to contain \"article\"\nError: Expected element to contain \"AuthorByline\"\nError: Expected element to contain \"{commentsEnabled: true}\"\n```\n\n#### `.toNotContain(selector)`\nAsserts the component does not contain the given selector.\n\n\u003e **Note:** accepts the same types as [`.toContain`](#tocontainselector)\n\n```js\n// This search should not have a search result.\nexpect(search).toNotContain('SearchResult')\n```\n\n##### Error\n\n```plain\nError: Expected element to not contain \"SearchResult\"\n```\n\n### Extensions\nNew methods added for `expect` assertions.\n\n- [.toHaveProp](#tohavepropname-value)\n- [.toHaveProps](#tohavepropsprops)\n- [.toHaveClass](#tohaveclassclassname)\n- [.toHaveState](#tohavestatestate)\n- [.toHaveRendered](#tohaverenderedelement)\n- [.toHaveStyle](#tohavestyleobject--property-value)\n- [.toHaveContext](#tohavecontextcontext)\n\n\n#### `.toHaveProp(name, [value])`\nAsserts a component was given a prop, and optionally specifies its value.\n\n```js\n// Assert the element has the prop \"disabled\".\nexpect(element).toHaveProp('disabled')\n\n// Assert the value of the users' name.\nexpect(user).toHaveProp('name', 'l33t_hackzor')\n```\n\n##### Error\n\n```plain\nError: Expected div to have prop \"disabled\"\nError: Expected User property \"name\" to be \"l33t_hackzor\"\n```\n\n\u003e Negation: `.toNotHaveProp()`\n\n#### `.toHaveProps({...props})`\nAsserts a component has a set of properties.\n\n```js\n// Asserts the button has all these properties.\nexpect(button).toHaveProps({size: 'large', type: 'action'})\n```\n\n##### Error\n\n```plain\nError: Expected Button to have prop \"size\"\n```\n\n\u003e Negation: `.toNotHaveProps()`\n\n#### `.toHaveClass(className)`\nAsserts a component contains a class name.\n\n```js\n// This button should be disabled.\nexpect(button).toHaveClass('disabled')\n```\n\n##### Error\n\n```plain\nError: Expected button to have class \"disabled\"\n```\n\n\u003e Negation: `.toNotHaveClass()`\n\n#### `.toHaveState({...state})`\nAsserts a component contains specific state.\n\n```js\n// Throws if either property is different.\nexpect(counter).toHaveState({\n  isActive: true,\n  clickCount: 3,\n})\n```\n\n##### Error\n\n```plain\nError: Expected state \"clickCount\" to equal 3\n```\n\n\u003e Negation: `.toNotHaveState()`\n\n#### `.toHaveRendered(element)`\nAsserts the component rendered the given value, or just that it rendered _something_.\n\n```js\n// The first event looks exactly like this.\nexpect(calendar.find('Event').first()).toHaveRendered(\u003cEvent invites={invites} /\u003e)\n\n// This list should be empty.\nexpect(listOfRegrets).toHaveRendered(null)\n\n// I don't trust this button.\nexpect(stockAdvice).toHaveRendered(\u003cbutton disabled={false}\u003eBuy now!\u003c/button\u003e)\n\n// It exists and it didn't render `null`.\nexpect(singers.find('Elvis')).toHaveRendered()\n```\n\n##### Error\n\n```plain\nError: Expected element to equal:\n   \u003cEvent invites={Array[22]} /\u003e\n\nError: Expected element to equal \"null\"\n\nError: Expected element to equal:\n   \u003cbutton disabled={false}\u003eBuy now!\u003c/button\u003e\n\nError: Expected element to have rendered something\n```\n\n\u003e Negation: `.toNotHaveRendered()`\n\n#### `.toHaveStyle(Object || property, [value])`\nAsserts a component contains the given css. Specifying the value is optional.\n\n```js\n// This dialog should be hidden.\nexpect(dialog).toHaveStyle('display', 'none')\n\n// You don't need to specify the value, though.\nexpect(dialog).toHaveStyle('transition')\n\n// You can also assert a whole collection of styles.\nexpect(marquee).toHaveStyles({\n  fontFamily: 'comic-sans',\n  color: 'orange',\n})\n```\n\n##### Error\n\n```plain\nError: Expected Dialog to have css {display: 'none'}\nError: Expected Dialog to have css property \"transition\"\nError: Expected Marquee to have css {fontFamily: 'comic-sans'}\n```\n\n\u003e Negation: `.toNotHaveStyle()`\n\n#### `.toHaveContext({...context})`\nAsserts the component contains the given context.\n\nHonestly, this only comes in handy if you're ensuring the `contextTypes` incantation succeeded.\n\n\u003e **Note:** React's context API is fickle. Make sure you [read the docs](https://facebook.github.io/react/docs/context.html)\n  before doing anything crazy.\u003cbr /\u003e\n  Also, be sure to ask yourself why you're using the context API at all.\n\n```js\n// Ensure your component receives this context.\n// You'll probably never do this unless you're a hardcore React library developer.\nexpect(element).toHaveContext({\n  state: {\n    value: 'maybe',\n  },\n})\n```\n\n##### Error\n\n```plain\nError: Expected context property \"state\" to equal {value: 'maybe'}\n```\n\n\u003e Negation: `.toNotHaveContext()`\n\n## Support\n:star: Please star this repository to maintain my unbounded ego.\n\n:beetle: If you find a bug, an annoyance, or a feature you want, submit an issue and we'll brainstorm it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsychollama%2Fexpect-enzyme","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpsychollama%2Fexpect-enzyme","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsychollama%2Fexpect-enzyme/lists"}