generic-interceptor
Version:
Provide proxy handler for getting properties and executing functions
70 lines (67 loc) • 2.4 kB
text/typescript
import { caseDescribe, strategyIt } from "../shared/jest";
import { parameterName, loadStrategyToTemplate, caseTemplate } from "../shared/generic-strategy";
import { TestStrategyResult, TestStrategyIt } from "../shared/enum";
const template = loadStrategyToTemplate(caseTemplate, {
[]: {
[]: (dataset) => ({
[]: () => {
throw dataset.functionError;
},
}),
[]: (dataset) => ({
[]: () => {
return dataset.functionResult;
},
}),
},
[]: {
[]: (dataset) => ({
[]: () => ({
[]: async () => {
throw dataset.functionError;
},
}),
}),
[]: (dataset) => ({
[]: () => ({
[]: async () => dataset.functionResult,
}),
}),
},
[]: {
[]: (dataset) => ({
[]: async () => {
throw dataset.functionError;
},
}),
[]: (dataset) => ({
[]: async () => dataset.functionResult,
}),
},
});
caseDescribe("<arrow function case>", () => {
strategyIt(
"<synchronous strategy> <function error result>",
template(TestStrategyIt.synchronousStrategy, TestStrategyResult.functionError),
);
strategyIt(
"<synchronous strategy> <function success result>",
template(TestStrategyIt.synchronousStrategy, TestStrategyResult.functionSuccess),
);
strategyIt(
"<callback ending strategy> <function error result>",
template(TestStrategyIt.callbackEndingStrategy, TestStrategyResult.functionError),
);
strategyIt(
"<callback ending strategy> <function success result>",
template(TestStrategyIt.callbackEndingStrategy, TestStrategyResult.functionSuccess),
);
strategyIt(
"<promise async strategy> <function error result>",
template(TestStrategyIt.promiseStrategy, TestStrategyResult.functionError),
);
strategyIt(
"<promise async strategy> <function success result>",
template(TestStrategyIt.promiseStrategy, TestStrategyResult.functionSuccess),
);
});