https://github.com/enzoferey/jest-test-my-code
Test code server side with Jest
https://github.com/enzoferey/jest-test-my-code
jest serverside testing
Last synced: 2 months ago
JSON representation
Test code server side with Jest
- Host: GitHub
- URL: https://github.com/enzoferey/jest-test-my-code
- Owner: enzoferey
- License: mit
- Created: 2018-08-29T10:35:48.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-09T00:00:32.000Z (over 7 years ago)
- Last Synced: 2025-03-18T21:54:36.345Z (over 1 year ago)
- Topics: jest, serverside, testing
- Language: JavaScript
- Size: 62.5 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jest-test-my-code
Test code server side with Jest
This is for demonstration purposes, feel free to fork it and adapt it to your use case.
## Usage
1. Clone repository
2. Start server running `npm start`
**Test JS code example**
3. Make a POST request with an `application/json` body like:
```json
{
"test": "add",
"code": "your code stringified here"
}
```
**Test React component example**
3. Make a POST request with an `application/json` body like:
```json
{
"test": "MyText",
"code": "import React from \"react\"; const MyText = ({ name }) =>
Hello ${name}
;"
}
```
## Notes
The method used right now is to expose user code in the global object through Jest's `setupFrameworkFile`, creating one setup file per user.
Another option could be to write received code to `__tests__/tmp//index.js`, clone the test file to that same directory and use the default export of `index.js` as the test function.