Routes tester for node.js
Created by: Alexandria
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
-
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: "me@gmail.com", password: "123", }, }, { answer: { user: { name: "string", email: "string", age: "number" }, access: "string" }, url: "user", method: "GET", comparation: "INTERFACE", params: { email: "me@gmail.com" } } ])
-
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")