parent
30c963a5f0
commit
61a1c93f0f
89 changed files with 15859 additions and 2 deletions
73
client/tests/test_helper.js
Normal file
73
client/tests/test_helper.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
// function should be called after async operation is finished
|
||||
export function execFuncs(instance, execs) {
|
||||
// instance: enzyme mounted component
|
||||
// const execs = [
|
||||
// {
|
||||
// func: "componentWillMount",
|
||||
// args: []
|
||||
// }
|
||||
// ];
|
||||
return execs.reduce((prePromise, nextFunc) => {
|
||||
return prePromise.then(() => instance[nextFunc.func](...nextFunc.args));
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
export function execsToStr(execs) {
|
||||
// const execs = [
|
||||
// {
|
||||
// func: "componentWillMount",
|
||||
// args: []
|
||||
// }
|
||||
// ];
|
||||
const execList = execs.map(
|
||||
funcInfo => `${funcInfo.func}(${funcInfo.args.join(", ")})`
|
||||
);
|
||||
|
||||
return execList.join(", ");
|
||||
}
|
||||
|
||||
export function getDesc(componentName, testCase) {
|
||||
// const testCase = {
|
||||
// execs: [
|
||||
// {
|
||||
// func: "onAddLocalFiles",
|
||||
// args: []
|
||||
// }
|
||||
// ],
|
||||
// state: {
|
||||
// filterFileName: ""
|
||||
// },
|
||||
// calls: [
|
||||
// {
|
||||
// func: "onAddLocalFiles",
|
||||
// count: 1
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
return `${componentName} should satisfy following by exec ${execsToStr(
|
||||
testCase.execs
|
||||
)}
|
||||
state=${JSON.stringify(testCase.state)}
|
||||
calls=${JSON.stringify(testCase.calls)} `;
|
||||
}
|
||||
|
||||
export function verifyCalls(calls, stubs) {
|
||||
// const calls: [
|
||||
// {
|
||||
// func: "funcName",
|
||||
// count: 1
|
||||
// }
|
||||
// ];
|
||||
// const stubs = {
|
||||
// funcName: jest.fn(),
|
||||
// };
|
||||
let err = null;
|
||||
calls.forEach(called => {
|
||||
if (stubs[called.func].mock.calls.length != called.count) {
|
||||
err = `InfoBar: ${called.func} should be called ${called.count} but ${
|
||||
stubs[called.func].mock.calls.length
|
||||
}`;
|
||||
}
|
||||
});
|
||||
return err;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue