diff --git a/package/spec/editor/collections/widgetsCollection-spec.js b/package/spec/editor/collections/widgetsCollection-spec.js index e52d74543..43705724c 100644 --- a/package/spec/editor/collections/widgetsCollection-spec.js +++ b/package/spec/editor/collections/widgetsCollection-spec.js @@ -32,4 +32,19 @@ describe('WidgetsCollection', () => { expect(subsetCollection.pluck('type_name')).toEqual(['consent_bar']); }); + + it('ignores null widgets', () => { + const widgetTypes = factories.widgetTypes([ + {role: 'consent', name: 'consent_bar', insertPoint: 'react'} + ]); + const widgets = new WidgetsCollection([ + {type_name: 'consent_bar', role: 'consent'}, + {type_name: null, role: 'other'}, + ], {widgetTypes}); + widgets.subject = factories.entry(); + + const subsetCollection = widgets.withInsertPoint('react'); + + expect(subsetCollection.pluck('type_name')).toEqual(['consent_bar']); + }); }); diff --git a/package/src/editor/collections/WidgetsCollection.js b/package/src/editor/collections/WidgetsCollection.js index a5e844d16..c5375a683 100644 --- a/package/src/editor/collections/WidgetsCollection.js +++ b/package/src/editor/collections/WidgetsCollection.js @@ -39,7 +39,9 @@ export const WidgetsCollection = Backbone.Collection.extend({ return new SubsetCollection({ parent: this, watchAttribute: 'type_name', - filter: widget => widget.widgetType().insertPoint === insertPoint + filter: widget => ( + widget.widgetType() && widget.widgetType().insertPoint === insertPoint + ) }); } });