semtest
Version:
NodeJs Unit test framework combining Tape, Proxyquire and Sinon
170 lines (167 loc) • 5.14 kB
JavaScript
import {
executeTests,
executeTestsInternal,
utilityFunctions
} from "./main";
executeTests("Test helpers library", [{
name: "executeTestsInternal",
assertions: [{
when: "given a test engine, a module name, and an assertion block",
should: "call the test engine accordingly",
test: function(t) {
t.plan(1);
const tapeMock = () => t.pass("");
executeTestsInternal(tapeMock)("", [{
assertions: ["foo"]
}]);
t.end();
}
}, {
when: "given a test engine, a module name, and an assertion block having an 'only' annoted assertion",
should: "call the test engine accordingly",
test: function(t) {
t.plan(1);
const tapeMock = {
only: () => t.pass("")
};
executeTestsInternal(tapeMock)("", [{
assertions: [{
only: true
}]
}]);
t.end();
}
}, {
when: "given a test engine, a module name, and an assertion block having a 'skip' annoted assertion",
should: "call the test engine accordingly",
test: function(t) {
t.plan(1);
const tapeMock = {
skip: () => t.pass("")
};
executeTestsInternal(tapeMock)("", [{
assertions: [{
skip: true
}]
}]);
t.end();
}
}]
}, {
name: "idFn",
assertions: [{
when: "given any input",
should: "return the same value",
test: (t) => utilityFunctions.resolveFn(
t.equal(
utilityFunctions.idFn("foo"),
"foo"))
}]
}, {
name: "idFnHO",
assertions: [{
when: "given any input",
should: "return the identity function",
test: (t) => utilityFunctions.resolveFn(
t.equal(
utilityFunctions.idFnHO()("foo"),
"foo"))
}]
}, {
name: "nullFn",
assertions: [{
when: "given any input",
should: "return null",
test: (t) => utilityFunctions.resolveFn(
t.equal(
utilityFunctions.nullFn(),
null))
}]
}, {
name: "nullFnHO",
assertions: [{
when: "given any input",
should: "return a function that returns null",
test: (t) => utilityFunctions.resolveFn(
t.equal(
utilityFunctions.nullFnHO()(),
null))
}]
}, {
name: "thrownFn",
assertions: [{
when: "given any input",
should: "throw an error",
test: (t) => utilityFunctions.resolveFn(
t.throws(utilityFunctions.throwFn))
}]
}, {
name: "throwFnHO",
assertions: [{
when: "given any input",
should: "return a function that throws an error",
test: (t) => utilityFunctions.resolveFn(
t.throws(utilityFunctions.throwFnHO())
)
}]
}, {
name: "resolveFn",
assertions: [{
when: "given any input",
should: "return a resolved Promise",
test: (t) => utilityFunctions.resolveFn(
utilityFunctions.resolveFn().then(() => t.pass("")))
}]
}, {
name: "resolveFnHO",
assertions: [{
when: "given any input",
should: "return a function that returns a resolved Promise",
test: (t) => utilityFunctions.resolveFn(
utilityFunctions.resolveFnHO()()
.then(() => t.pass("")))
}]
}, {
name: "rejectFn",
assertions: [{
when: "given any input",
should: "return a rejected Promise",
test: (t) => utilityFunctions.resolveFn(
utilityFunctions.rejectFn()
.catch(() => t.pass("")))
}]
}, {
name: "rejectFnHO",
assertions: [{
when: "its returned function is not given a rejection reason",
should: "return a function that returns the base reason",
test: (t) =>
utilityFunctions.rejectFnHO("foo")()
.catch((rejection) => t.equal(
rejection.message,
"foo"))
}, {
when: "its returned function is given a rejection reason",
should: "return a function that returns the given reason",
test: (t) =>
utilityFunctions.rejectFnHO("foo")("bar")
.catch((rejection) => t.equal(
rejection.message,
"bar"))
}]
}, {
name: "createResponseMock",
assertions: [{
should: "return an object that has a status method which alter the response status",
test: (t) => utilityFunctions.resolveFn(
t.equal(
utilityFunctions.createResponseMock().status("foo").status,
"foo"))
}, {
should: "return an object that has a json method which alter the response body",
test: (t) => utilityFunctions.resolveFn(
t.equal(
utilityFunctions.createResponseMock().json("foo").body,
"foo"))
}]
}]);