Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kentcdodds/js-mocking-fundamentals
JavaScript Mocking Fundamentals on TestingJavaScript.com
https://github.com/kentcdodds/js-mocking-fundamentals
kcd-edu mocking testing testingjavascript
Last synced: 4 days ago
JSON representation
JavaScript Mocking Fundamentals on TestingJavaScript.com
- Host: GitHub
- URL: https://github.com/kentcdodds/js-mocking-fundamentals
- Owner: kentcdodds
- License: other
- Created: 2018-06-20T03:23:36.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-02-01T15:49:05.000Z (12 months ago)
- Last Synced: 2024-10-19T18:25:30.189Z (3 months ago)
- Topics: kcd-edu, mocking, testing, testingjavascript
- Language: JavaScript
- Homepage: https://testingjavascript.com/courses/javascript-mocking-fundamentals
- Size: 172 KB
- Stars: 306
- Watchers: 12
- Forks: 286
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.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.