# jest-change-matchers

> Change matcher for Jest inspired by RSpec.

Latest version **1.0.1** (published 2018-05-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install jest-change-matchers
pnpm add jest-change-matchers
yarn add jest-change-matchers
bun add jest-change-matchers
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-05-26 |
| First published | 2018-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 266.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Martin Fernandez |
| Maintainers | bilby91 |
| Keywords | jest, node, change, matchers, rspec |

## Links

- npm: https://www.npmjs.com/package/jest-change-matchers
- Repository: https://github.com/bilby91/jest-change-matchers
- Homepage: https://github.com/bilby91/jest-change-matchers#readme
- Issues: https://github.com/bilby91/jest-change-matchers/issues
- npm.io page: https://npm.io/package/jest-change-matchers

## Dependencies (1)

- [jest](https://npm.io/package/jest.md) ^23.0.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-05-26
- 1.0.0 — 2018-05-26

## README

# jest-change-matchers [![npm version](https://badge.fury.io/js/jest-change-matchers.svg)](https://badge.fury.io/js/jest-change-matchers) [![codecov](https://codecov.io/gh/bilby91/jest-change-matchers/branch/master/graph/badge.svg)](https://codecov.io/gh/bilby91/jest-change-matchers) [![CircleCI](https://circleci.com/gh/bilby91/jest-change-matchers/tree/master.svg?style=svg)](https://circleci.com/gh/bilby91/jest-change-matchers/tree/master)

Jest matchers to evaluate side effect changes.

## Installation

```shell
yarn add --dev jest-change-matchers
```

## Usage

After installing the packge you will have a few more matchers in your toolbelt. If you are familiar with RSpec, the new matchers
should make you feel like home :).

### toChange

```javascript
describe("toChange", () => {
  beforeEach(() => {
    sharedState = 0
  })

  describe(".toChange", () => {
    it("passes when there is a change", async () => {
      await expect(async () => {
        sharedState += 1
      }).toChange(async () => {
        return sharedState
      })
    })

    it("throws an error when there is no change", async () => {
      const testCase = () => {
        return expect(async () => {
          sharedState += 0
        }).toChange(async () => {
          return sharedState
        })
      }

      await expect(testCase()).rejects.toThrowErrorMatchingSnapshot()
    })
  })

  describe(".not.toChange", () => {
    it("passes when there is no change", async () => {
      await expect(async () => {
        // no-op
      }).not.toChange(async () => {
        return sharedState
      })
    })

    it("throws an error when there is a change", async () => {
      const testCase = () => {
        return expect(async () => {
          sharedState += 1
        }).not.toChange(async () => {
          return sharedState
        })
      }

      await expect(testCase()).rejects.toThrowErrorMatchingSnapshot()
    })
  })
})
```

### toChangeBy

```javascript
describe("toChangeBy", () => {
  beforeEach(() => {
    sharedState = 0
  })

  describe(".toChangeBy", () => {
    it("passes with positive changes", async () => {
      await expect(async () => {
        sharedState += 1
      }).toChangeBy(async () => {
        return sharedState
      }, 1)
    })

    it("passes with negative changes", async () => {
      await expect(async () => {
        sharedState -= 1
      }).toChangeBy(async () => {
        return sharedState
      }, -1)
    })

    it("throws an error when it doesn't change the desired amount", async () => {
      const testCase = () => {
        return expect(async () => {
          sharedState += 2
        }).toChangeBy(async () => {
          return sharedState
        }, 1)
      }

      await expect(testCase()).rejects.toThrowErrorMatchingSnapshot()
    })
  })

  describe(".not.toChangeBy", () => {
    it("passes with positive changes", async () => {
      await expect(async () => {
        sharedState += 1
      }).not.toChangeBy(async () => {
        return sharedState
      }, -1)
    })

    it("passes with negative changes", async () => {
      await expect(async () => {
        sharedState -= 1
      }).not.toChangeBy(async () => {
        return sharedState
      }, 1)
    })

    it("throws an error when it changes the desired amount", async () => {
      const testCase = () => {
        return expect(async () => {
          sharedState += 2
        }).not.toChangeBy(async () => {
          return sharedState
        }, 2)
      }

      await expect(testCase()).rejects.toThrowErrorMatchingSnapshot()
    })
  })
})
```

### toChangeFromTo

```javascript
describe("toChangeFromTo", () => {
  beforeEach(() => {
    sharedState = 0
  })

  describe(".toChangeFromTo", () => {
    it("passes when it changes from previous and new value", async () => {
      await expect(async () => {
        sharedState += 1
      }).toChangeFromTo(async () => {
        return sharedState
      }, 0, 1)
    })

    it("throws an error when it doesn't change from previous value", async () => {
      const testCase = () => {
        return expect(async () => {
          sharedState += 2
        }).toChangeFromTo(async () => {
          return sharedState
        }, 1, 2)
      }

      await expect(testCase()).rejects.toThrowErrorMatchingSnapshot()
    })

    it("throws an error when it doesn't change to new value", async () => {
      const testCase = () => {
        return expect(async () => {
          sharedState += 2
        }).toChangeFromTo(async () => {
          return sharedState
        }, 0, 1)
      }

      await expect(testCase()).rejects.toThrowErrorMatchingSnapshot()
    })
  })

  describe(".not.toChangeFromTo", () => {
    it("passes when it doesn't change to previous and new value", async () => {
      await expect(async () => {
        sharedState += 1
      }).not.toChangeFromTo(async () => {
        return sharedState
      }, 0, 0)
    })

    it("throws an error when it change to previous and new value", async () => {
      const testCase = () => {
        return expect(async () => {
          sharedState += 2
        }).not.toChangeFromTo(async () => {
          return sharedState
        }, 0, 2)
      }

      await expect(testCase()).rejects.toThrowErrorMatchingSnapshot()
    })

  })
})
```

## Contact

- Martín Fernández <fmartin91@gmail.com>

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