fix(last-n-limits): crash on undefined
This commit is contained in:
parent
b3b561f27a
commit
4adaa6f1fd
|
@ -40,6 +40,10 @@ export function validateLastNLimits(lastNLimits) {
|
||||||
* of participants or {@code undefined} otherwise.
|
* of participants or {@code undefined} otherwise.
|
||||||
*/
|
*/
|
||||||
export function limitLastN(participantsCount, lastNLimits) {
|
export function limitLastN(participantsCount, lastNLimits) {
|
||||||
|
if (!lastNLimits || !lastNLimits.keys) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
let selectedLimit;
|
let selectedLimit;
|
||||||
|
|
||||||
for (const participantsN of lastNLimits.keys()) {
|
for (const participantsN of lastNLimits.keys()) {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import { limitLastN, validateLastNLimits } from './functions';
|
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', () => {
|
describe('when a correct limit mapping is given', () => {
|
||||||
const limits = new Map();
|
const limits = new Map();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue