Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niraj-khatiwada/node-jest
Testing in Node.js using Jest
https://github.com/niraj-khatiwada/node-jest
Last synced: about 1 month ago
JSON representation
Testing in Node.js using Jest
- Host: GitHub
- URL: https://github.com/niraj-khatiwada/node-jest
- Owner: niraj-khatiwada
- Created: 2023-10-18T07:07:02.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-25T15:19:52.000Z (about 1 year ago)
- Last Synced: 2023-10-26T13:35:33.820Z (about 1 year ago)
- Language: TypeScript
- Size: 113 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AAA principle:
- arrange
- act
- assert# Test Doubles
### Stubs:
- In stubs, you expect a pre-defined output. for eg: success, failure, exception, etc.
- Is the return type correct based on the parameters passed?### Fakes:
- Fakes are the closest thing that a testing environment when compared to real feature
- For eg: If you want to connect to Google services, instead of connecting to Google in tests, you create a fake http server that mimics as Google server.
- Or you create a fake database implementation that mimics the actual database. Maybe use a in memory SQLite database as fake db.
- Fakes causes limitation where even if you provide very simple implementation not covering all aspect of tests, the test coverage might say 100%. That is solved by mocks.### Mocks:
- When you want to mock the implementation of a function or a method
- Was the function called correctly? How many times it was called?
- Are the parameters correct?
- Mocks usually do not test the return values. Those are done using stubs.### Spies:
- Similar to mocks but usually used to mock the methods of an object
# TDD: Test Driven Development
- Chicago vs London
### Chicago
- A unit = collection of pieces working together to make a feature.
- Tests from a broader view
- Little use of mocks### London
- A unit = a class
- heavy usage of mocks. Mocks all of the dependencies