https://github.com/danielcaldas/test-fixtures-pattern
A simple demonstration of a fixtures test based architecture in JavaScript
https://github.com/danielcaldas/test-fixtures-pattern
architectural-patterns javascript jest testing unit-testing
Last synced: 23 days ago
JSON representation
A simple demonstration of a fixtures test based architecture in JavaScript
- Host: GitHub
- URL: https://github.com/danielcaldas/test-fixtures-pattern
- Owner: danielcaldas
- License: gpl-3.0
- Created: 2019-10-03T13:47:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-18T15:09:36.000Z (about 2 years ago)
- Last Synced: 2025-03-24T03:04:59.760Z (about 1 month ago)
- Topics: architectural-patterns, javascript, jest, testing, unit-testing
- Language: JavaScript
- Homepage: https://goodguydaniel.com/blog/unit-testing-with-fixtures-unleashed/
- Size: 639 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unit testing with fixtures unleashed
This repository is just an example for explaining how fixtures can be set up in within a project, you can read more about it [in this blog post](https://goodguydaniel.com/blog/unit-testing-with-fixtures-unleashed/).A simple demonstration of a fixtures test based architecture in JavaScript. A simple case study scenario is built around a function called `backgroundColorReplacer` that is exposed in main *entroypoint* file `replacer.js`.
## The case study
There's a dummy implementation of a function called `backgroundColorReplacer` that basically replaces a `background-color` css property with a `rgb` color for some other `rgb` or `rgba` color depending on the options passed to this function.Examples of usage can be seen in the file `__tests__/replacer.test.js`.
### Unit tests
Some simple unit tests are added in `__tests__/replacer.test.js`, as a first step.
branch: step-1-implementation-and-unit-tests### Fixtures architecture
At the end, we get a set of organized test cases within the `fixtures` folder, that are consumed from `run-fixtures.js` that will generate all the *jest boilerplatish* code for us. Each test case within `fixtures` has a very specific name that depicts its purpose, also the content of these files is strictly declarative,
the only thing there are the specification of the inputs for our replacer.```
fixtures
├── not-replace-color-if-no-match.js
├── not-replace-color-if-no-new-color-specified.js
├── replace-color-when-match-and-opacity-defined.js
├── replace-color-when-match.js
└── tests
├── fixtures.spec.js
└── __snapshots__
└── fixtures.spec.js.snap
run-fixtures.js
```- `fixtures` - folder where test cases are specified.
- `run-fixtures` - responsible for generating `fixtures/tests/fixtures.spec.js`, where the actual tests are outputted.✍️ ["Unit testing with fixtures unleashed"](https://goodguydaniel.com/blog/unit-testing-with-fixtures-unleashed/) @ [goodguydaniel.com](https://goodguydaniel.com)