https://github.com/adamslack/handlebars-express-testing
Example of unit testing handlebars with express like you might test a react component.
https://github.com/adamslack/handlebars-express-testing
Last synced: 3 months ago
JSON representation
Example of unit testing handlebars with express like you might test a react component.
- Host: GitHub
- URL: https://github.com/adamslack/handlebars-express-testing
- Owner: AdamSlack
- Created: 2022-04-09T13:03:18.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-26T16:01:19.000Z (about 4 years ago)
- Last Synced: 2025-02-05T20:06:19.149Z (over 1 year ago)
- Language: HTML
- Size: 8.66 MB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Handlebars Express Testing
This is a sample project showing how you might test a handlebars w/ express app.
Example tests approach 2 different angles.
1. Testing the result of the express endpoints
2. Testing only a rendered template
Templates rendered via express and then returned from an API request use supertest to simulate the running and calling of the API.
Templates rendered separately to the API use the handlebars engine directly.
Tests both with and without express being involved use `cheerio` to allow you to query the rendered string.
This project levereages:
- `supertest` to simulate invoking express endpoints
- `cheerio` to load rendered HTML into a format easy to query
- `jest` to structure and run tests
## Getting started
Install dependencies: `npm install`
Run the tests: `npm run test`
Inspect the output in your console.
## Project structure
The express app has views and controllers.
The Controllers will pick a view to render and return that.
THe views consist of handlebars templates that will end up being rendered.
## Importing Handlebars Template Files
This project has a util function that will read the template using node's `fs` api. To allow the util to be imported and used from anywhere. The npm package `callsite` is used.