Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simotae14/js-mocking-fundamentals
javascript mocking monkey-patching solution
https://github.com/simotae14/js-mocking-fundamentals
Last synced: 9 days ago
JSON representation
javascript mocking monkey-patching solution
- Host: GitHub
- URL: https://github.com/simotae14/js-mocking-fundamentals
- Owner: simotae14
- Created: 2019-12-24T14:29:51.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T13:02:34.000Z (almost 2 years ago)
- Last Synced: 2024-04-17T05:04:44.599Z (7 months ago)
- Language: JavaScript
- Size: 854 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
JavaScript Mocking Fundamentals
Learn how mocking in JavaScript tests works by implementing them from scratch!
In this material, we have a set of `no-framework` tests that correspond to a set
of jest tests (in the `__tests__` directory). The idea is that (with the
exception of the first test), you look at the jest version first, then see how
that would be implemented without a testing framework.Order of material:
1. `monkey-patching.js` (no jest version)
2. `mock-fn.js`
3. `spy.js`
4. `inline-module-mock.js`
5. `external-mock-module.js`The files are intended to test the `thumb-war.js` module and mock the `utils`
module.To run the tests, run `npx jest`. To start watch mode run `npx jest --watch`
## Custom jest runner.
You can definitely run the `no-framework` files just using `node` (like this:
`node src/no-framework/monkey-patching.js`), but in an effort to make running
these easier, I created a custom jest runner that uses jest to run the files,
but allow them to be run without the jest testing framework. It's really cool.
It uses [`create-jest-runner`](https://www.npmjs.com/package/create-jest-runner)
and should probably be published eventually.