fix(last-n-limits): crash on undefined

This commit is contained in:
paweldomas 2020-08-04 08:16:00 -05:00 committed by Saúl Ibarra Corretgé
parent b3b561f27a
commit 4adaa6f1fd
2 changed files with 8 additions and 1 deletions

View File

@ -40,6 +40,10 @@ export function validateLastNLimits(lastNLimits) {
* of participants or {@code undefined} otherwise.
*/
export function limitLastN(participantsCount, lastNLimits) {
if (!lastNLimits || !lastNLimits.keys) {
return undefined;
}
let selectedLimit;
for (const participantsN of lastNLimits.keys()) {

View File

@ -1,6 +1,9 @@
import { limitLastN, validateLastNLimits } from './functions';
describe('limitsLastN', () => {
describe('limitLastN', () => {
it('handles undefined mapping', () => {
expect(limitLastN(0, undefined)).toBe(undefined);
});
describe('when a correct limit mapping is given', () => {
const limits = new Map();