I am writing my first set of unit tests for typescript code and having hard time figuring our how to test processRecord
method since it doesn't return the array that contains key logic output.
export const processRecord = async (event, context: AppContext) => {
if (!event.Records) {
return false;
}
const promises = event.Records.map(async (record: DynamoDBRecord) => {
try {
if (!record.dynamodb) {
return false;
}
let newInsuranceNamesList: string[] = [];
...
// some logic to update newInsuranceNamesList
...
await sendTo3rdParty(newInsuranceNamesList);
} catch (err) {
console.error(err);
}
});
return Promise.all(promises);
};
Checking when event.Records
or record.dynamodb
doesn't exist is easy because it returns false
. But the only real way for me to test processRecord
is by checking contents of newInsuranceNamesList
array. How can I achieve it in unit test?
figured it out, simple answer - refactor and pull the logic that determines newInsuranceNamesList
into its own method and unit test it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.