Jest testing

https://jestjs.io/docs/getting-started

Test callback

const test = (fetch) => {
	return fetch("test");
};

module.exports = test;
const testFunction = require("./index");

test("test callback function", (done) => {

	function fetch(data) {

			try {

					expect(data).toBe("test_fake");

					done();

			} catch (error) {

					done(error);

			}

	}

	testFunction(fetch);

});

========================================================================

Test string => toMatch(some_regex)

Test value => toBe(value_expect)

========================================================================

Test promise:

const fetchData = require("./index");

test("test promise", () => {
  return fetchData().then((data) => {
    expect(data).toBe("hello");
  });
});

========================================================================

Test function with async/await

index.test.js

const fetchData = require("./index");

test("test async function", async () => {
  const data = await fetchData();
  expect(data).toBe("hello");
});

index.js