Test removeAt does not fire event for invalid index

This commit is contained in:
Maximilian Krög
2022-07-30 02:53:35 +02:00
parent 217230172b
commit 6f539c9ca4

View File

@@ -5,6 +5,7 @@ import sinon from 'sinon';
import {listen} from '../../../src/ol/events.js'; import {listen} from '../../../src/ol/events.js';
describe('ol/Collection.js', function () { describe('ol/Collection.js', function () {
/** @type {Collection} */
let collection; let collection;
beforeEach(function () { beforeEach(function () {
@@ -86,6 +87,13 @@ describe('ol/Collection.js', function () {
expect(collection.item(0)).to.eql(0); expect(collection.item(0)).to.eql(0);
expect(collection.item(1)).to.eql(2); expect(collection.item(1)).to.eql(2);
}); });
it('does not fire event for invalid index', function () {
const collection = new Collection([0, 1, 2]);
collection.on('remove', function () {
throw new Error('Should not fire event for invalid index');
});
expect(collection.removeAt(3)).to.be(undefined);
});
}); });
describe('forEach', function () { describe('forEach', function () {