Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rincedd/rewire-test-helper
https://github.com/rincedd/rewire-test-helper
mocha mocking rewire testing testing-tools
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rincedd/rewire-test-helper
- Owner: rincedd
- License: mit
- Created: 2016-07-06T13:07:17.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-24T16:54:26.000Z (over 7 years ago)
- Last Synced: 2023-12-23T16:19:59.514Z (about 1 year ago)
- Topics: mocha, mocking, rewire, testing, testing-tools
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rewire-test-helper
[![Build Status](https://travis-ci.org/rincedd/rewire-test-helper.svg?branch=master)](https://travis-ci.org/rincedd/rewire-test-helper)---
**DEPRECATED:** Prefer using `__rewire_reset_all__()` provided by `babel-plugin-rewire`
since version 1.1.0! This is safer and does not accumulate calls to global afterEach hooks.---
Simplify working with `babel-plugin-rewire`. Automatically reset
rewired dependencies in your testing framework's `afterEach` hook.## Usage
Use with, e.g., `mocha`, `chai`, and `sinon`.
```javascript
import {someMethod, __RewireAPI__} from './module-to-test';
import {rewire} from 'rewire-test-helper';describe('someMethod', function() {
const moduleToTest = rewire(__RewireAPI__);it('should do something', function() {
const importedFunctionStub = sinon.stub();
moduleToTest.replace('anImportedFunction', importedFunctionStub);someMethod();
expect(importedFunctionStub).to.have.been.called;
});
});
```Any imported dependency in `module-to-test` can be replaced by something
else using `replace`. By default, all imports will be reset after each test
using the `afterEach` hook of the test framework.