# react-spy-on-render

> Spy on rendering of React components with Jasmine

Latest version **0.7.0** (published 2019-01-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-spy-on-render
pnpm add react-spy-on-render
yarn add react-spy-on-render
bun add react-spy-on-render
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.0 |
| Published | 2019-01-10 |
| First published | 2018-03-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 189 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Reid Mitchell |
| Maintainers | reid47 |
| Keywords | jasmine, react |

## Links

- npm: https://www.npmjs.com/package/react-spy-on-render
- Repository: https://github.com/reid47/react-spy-on-render
- Homepage: https://github.com/reid47/react-spy-on-render#readme
- Issues: https://github.com/reid47/react-spy-on-render/issues
- npm.io page: https://npm.io/package/react-spy-on-render

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^0.14.8 || ^15.0.1 || ^16.0.0
- [react-element-to-jsx-string](https://npm.io/package/react-element-to-jsx-string.md) ^13.2.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.7.0 (latest) — 2019-01-10
- 0.6.0 — 2018-07-23
- 0.5.0 — 2018-03-26
- 0.4.0 — 2018-03-17
- 0.3.0 — 2018-03-17
- 0.2.0 — 2018-03-17
- 0.1.0 — 2018-03-17

## README

# react-spy-on-render

Spy on React components in Jasmine tests.

**DOES NOT WORK WITH FUNCTIONAL COMPONENTS**. They're functions!

## Installation

```sh
yarn add -D react-spy-on-render
# or
npm install react-spy-on-render --save-dev
```

Put this in your `spec_helper.js`:

```js
import 'react-spy-on-render';
// or
require('react-spy-on-render');
```

## Usage

### spyOnRender

Just call it:

```js
spyOnRender(Component);
```

By default, it won't render anything. If you want to render normally:

```js
spyOnRender(Component).and.callThrough();
```

`spyOnRender` returns a spy, so you can do whatever you want with it.

### Matchers

Was the component rendered?

```js
expect(Component).toHaveBeenRendered();
```

Was the component rendered _at any point_ with specific props?

```js
expect(Component).toHaveBeenRenderedWithProps({
  className: 'some-class',
  otherProp: 47
});
```

Was the component _last_ rendered with specific props?

```js
expect(Component).toHaveBeenRenderedLastWithProps({
  className: 'some-class',
  otherProp: 47
});
```

Was the component rendered a specific number of times?

```js
expect(Component).toHaveBeenRenderedTimes(4);
```

### Helpers

Reset all tracked renders on a component:

```js
resetRenders(Component);
```

What props were rendered last?

```js
propsOnLastRender(Component);
```

What props were rendered at some other point in time?

```js
propsOnRenderAt(Component, i);
```

## Development

Use `yarn test` to start up a local Jasmine to run the tests in a browser. It watches your files for changes and automatically recompiles them with Webpack.

Use `yarn build` to transpile the source into the `dist` folder (in preparation for publishing on NPM).

## Acknowledgements

This project drew a lot of inspiration and much of its code from [this great project](https://github.com/atomanyih/spy-on-render).

---
_Source: https://npm.io/package/react-spy-on-render · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
