starless-unit-test
v1.0.1
Published
Command Line Unit Testing tool.
Downloads
1
Readme
Starless Unit Test
Command Line Unit Testing tool.
Installation
npm install -g starless-unit-test
Getting Started
Let's get started by writing a test for a hypothetical function that adds two numbers. First, create a calculator.js
file under utils
folder:
function sum(a, b) {
return a + b;
}
exports.sum = sum;
Then, create a file named calculator.json
. This will contain our actual test:
{
"adds 1 + 2 to equal 3": {
"type": "function",
"scriptPath": "./utils",
"function": "calculator.sum",
"expect": [1, 2],
"toBe": 3
}
}
Finally, run starless-unit-test calculator.json
and it will print this message:
PASS ./calculator.test.js
✓ adds 1 + 2 to equal 3 (5ms)
You just successfully wrote your first test using Starless Unit Test program!
API Test
You can also test for api endpoints. Response format for api is like this {data: {}, status: 200}
. That's why we add expectArg
to data.data
.
{
"adds 1 + 2 to equal 3": {
"type": "api",
"expect": {
"url": "http://localhost:3000/sum",
"method": "post"
"body": {
"a": 1,
"b": 2
}
},
"expectArg": "data.data",
"toBe": 3
}
}
Test With Browser
You can also test from browser. Puppeteer is used for testing with browser.
{
"Is starless unit test package existed?": {
"type": "browser",
"expect": [
{
"action": "goto",
"args": [
"'https://www.npmjs.com/package/starless-unit-test'",
{
"waitUntil": "networkidle2"
}
]
},
{
"action": "evaluate",
"args": [
"(selector) => {return document.querySelector(selector).textContent;}",
"'#readme h1'"
]
}
],
"toBe": "'Starless Unit Test'"
}
}
More Resources
Jest is internally used for unit testing. You can see more at Jest .