testinha
v0.1.5
Published
Testing library for Node.js by Alexandria
Downloads
22
Maintainers
Readme
Testinha
Routes tester for node.js
Created by: Alexandria
Installing
Using npm:
npm install testinha
Using npm as dev dependence:
npm install testinha --save-dev
Using yarn:
yarn add testinha
Using yarn as dev dependence:
yarn add testinha -D
Dependencies
How to use it
Starting an instance of Testinha
const test = Testinha("https://google.com", 80);
Changing the base url
test.changeBaseUrl("https://google.com");
Changing the port
test.changePort("80");
Testing a route
test.testOne({ answer: { error: "No data provided" }, url: "test", method: "GET", comparation: "EQUAL", params: { data: "no data" } }).then(res => console.log(res))
Testing many routes
test.test([ { answer: { error: "No data provided" }, url: "test", method: "GET", comparation: "EQUAL", params: { data: "no data" } }, { answer: "", url: "login", method: "POST", comparation: "TYPE", body: { email: "[email protected]", password: "123", }, }, { answer: { user: { name: "string", email: "string", age: "number" }, access: "string" }, url: "user", method: "GET", comparation: "INTERFACE", params: { email: "[email protected]" } } ])
Params explanation
baseURL:
- The consistent part of the web address you want to test
port:
- The port of the web address you want to test
answer:
- The expected answer for the route
url:
- The route you want to test
method:
- The method used for the route
- Accepted methods: GET, POST, PUT, DELETE
- Defaults to: GET
comparation:
- The type of comparation between the expected answer and the received answer
- Accepted comparations: EQUAL, TYPE, INTERFACE
- Defaults to: EQUAL
- EQUAL: compares if the answers are exact the same
- TYPE: compares if the answers are the same type (objects are considered the same no matter theirs keys)
- INTERFACE: compares if the answer received has the exact same type as the expected answer defined (each objects keys are compared, unless the expected answer is "object")