Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jackall3n/enzyme-dive

Dive πŸŠπŸΌβ€β™‚οΈ
https://github.com/jackall3n/enzyme-dive

dive enzyme react testing typescript

Last synced: 4 days ago
JSON representation

Dive πŸŠπŸΌβ€β™‚οΈ

Awesome Lists containing this project

README

        

πŸŠπŸΌβ€β™‚ Dive deep️

## Installation

#### 1. Add Package
```typescript
yarn add enzyme-dive --dev
```

#### 2. Extend Enzyme in your setup file
```typescript
import * as Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-xx';
import configure from "enzyme-dive";

Enzyme.configure({ adapter: new Adapter() });

// The magic πŸ§™πŸΌβ€β™‚οΈ
configure(Enzyme.ShallowWrapper);
```

## Usage

### diveTo(selector)
Use this to dive until you reach your component. This can be useful if you've got many HoC wrappers.
```typescript
import React from 'react';
import { shallow } from "enzyme";
import Component from './Component';
import ChildComponent from './ChildComponent';

describe('', function() {
it("should render child", () => {
const wrapper = shallow().diveTo(ChildComponent);

expect(wrapper).toMatchSnapshot();
});
});
```
---
### diveDeep(depth)
Dive through your nodes a specified amount
```typescript
import React from 'react';
import { shallow } from "enzyme";
import Component from './Component';

describe('', function() {
it("should render", () => {
// const wrapper = shallow().dive().dive().dive().dive().dive();
const wrapper = shallow().diveDeep(5);

expect(wrapper).toMatchSnapshot();
});
});
```