{"id":21358072,"url":"https://github.com/iwtkachenko/hoc-enzyme","last_synced_at":"2025-07-05T16:34:09.905Z","repository":{"id":57264744,"uuid":"76072806","full_name":"iwtkachenko/hoc-enzyme","owner":"iwtkachenko","description":"Solving painful headless testing of React HOCs with enzyme ","archived":false,"fork":false,"pushed_at":"2016-12-18T14:46:07.000Z","size":48,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-19T03:14:30.009Z","etag":null,"topics":[],"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/iwtkachenko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-09T21:49:00.000Z","updated_at":"2017-08-24T21:35:18.000Z","dependencies_parsed_at":"2022-08-25T03:40:26.150Z","dependency_job_id":null,"html_url":"https://github.com/iwtkachenko/hoc-enzyme","commit_stats":null,"previous_names":["iwtkachenko/hoc-enzyme","vashigor/hoc-enzyme"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwtkachenko%2Fhoc-enzyme","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwtkachenko%2Fhoc-enzyme/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwtkachenko%2Fhoc-enzyme/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwtkachenko%2Fhoc-enzyme/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iwtkachenko","download_url":"https://codeload.github.com/iwtkachenko/hoc-enzyme/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225384390,"owners_count":17465879,"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":[],"created_at":"2024-11-22T05:14:13.025Z","updated_at":"2024-11-22T05:14:13.642Z","avatar_url":"https://github.com/iwtkachenko.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hoc-enzyme\nSolving painful headless testing of Relay-produced HOCs\n\nInstall\n-------\n\n1. npm install -D hoc-enzyme enzyme\n2. Edit your Mocha's setup.js\n  1. import HOCEnzyme from 'hoc-enzyme'\n  2. HOCEnzyme.setup()\n\nSyntax\n======\n```javascript\nwrapper.diveInto((child) =\u003e child.type() == Text)\n```\n\nWith DOM rendering (mounted components)\n=======================================\nUsage with Redux \u0026\u0026 react-native-router-flux\n--------------------------------------------\n```javascript\ndescribe('Sandboxed react-native-router-flux width redux', () =\u003e {\n  let wrapper\n\n  jsdom()\n\n  before(() =\u003e {\n    wrapper = mount(\u003cRouterComponent /\u003e)\n  })\n\n  it.only('should switch between views', () =\u003e {\n    let spy = sinon.spy(Actions, 'second')\n    const TmpCom = wrapper.find(RouterWithRedux).diveInto(\n      child =\u003e {\n        return child.type() == Scene \u0026\u0026 child.__unwrapped.key == 'home'\n      }\n    ).prop('component')\n    expect(store.getState()).to.have.deep.property('scene.sceneKey', 'home')\n    mount(\u003cTmpCom /\u003e).diveInto(\n      child =\u003e child.type() == TouchableHighlight\n    ).prop('onPress')()\n    expect(store.getState()).to.have.deep.property('scene.sceneKey', 'second')\n  })\n})\n```\n\nUsage with Apollo\n-----------------\n```javascript\ndescribe('Sandboxed react-native + apollo', () =\u003e {\n  let wrapper\n\n  jsdom()\n\n  before(() =\u003e {\n    wrapper = mount((\n      \u003cApolloProvider client={client}\u003e\n        \u003cSandboxComponent /\u003e\n      \u003c/ApolloProvider\u003e\n    ))\n  })\n\n  it('should fetch data from apollo component', () =\u003e {\n    const tmp = wrapper.find(SandboxComponent).diveInto((child) =\u003e {\n      return child.type() == Text\n    }, false)\n\n    expect(tmp.first()).to.have.props({children: 'Hello world'})\n  })\n})\n```\n\nUsage with Relay\n----------------\n```javascript\ndescribe('\u003cHome/\u003e', () =\u003e {\n  let wrapper = null\n\n  jsdom()\n\n  const counter = (child, node, index) =\u003e\n    node.type() == View \u0026\u0026 child.type() == Text \u0026\u0026 index == 2\n\n  const button = child =\u003e child.type() == TouchableHighlight\n\n  before(done =\u003e {\n    /**\n     * Home is a wrapped with Renderer Relay Container\n     * It renders the following jsx\n     * \u003cView\u003e\n     *   \u003cTouchableHighlight ...\u003e\n     *     \u003cText\u003e...\u003c/Text\u003e\n     *   \u003c/TouchableHighlight\u003e\n     *   \u003cText\u003e...\u003c/Text\u003e\n     *   \u003cText\u003e...\u003c/Text\u003e\n     * \u003c/View\u003e\n     */\n    wrapper = mount(\u003cHome /\u003e)\n    done()\n  })\n\n  it('should render select text', done =\u003e {\n    const view = wrapper.find(View)\n    // Use predicate to find not presented children\n    expect(view.diveInto(counter)).to.have.props({children: 0})\n\n    view.diveInto(button).prop('onPress')()\n    setTimeout(() =\u003e {\n      expect(view.diveInto(counter)).to.have.props({children: 1})\n      done()\n    }, 10)\n  })\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiwtkachenko%2Fhoc-enzyme","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiwtkachenko%2Fhoc-enzyme","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiwtkachenko%2Fhoc-enzyme/lists"}