diff --git a/src/utils/OrderedMap.js b/src/utils/OrderedMap.js index b4ea88216f..1bf238fd32 100644 --- a/src/utils/OrderedMap.js +++ b/src/utils/OrderedMap.js @@ -18,6 +18,7 @@ "use strict"; +var invariant = require('invariant'); var mixInto = require('mixInto'); var throwIf = require('throwIf'); @@ -349,6 +350,10 @@ var OrderedMapMethods = { mapKeyRange: function(cb, startKey, endKey, context) { var startIndex = this.indexOfKey(startKey); var endIndex = this.indexOfKey(endKey); + invariant( + startIndex !== undefined && endIndex !== undefined, + 'mapKeyRange must be given keys that are present.' + ); if (endIndex < startIndex) { throw new Error(RANGE_ARGS); } @@ -358,6 +363,10 @@ var OrderedMapMethods = { forEachKeyRange: function(cb, startKey, endKey, context) { var startIndex = this.indexOfKey(startKey); var endIndex = this.indexOfKey(endKey); + invariant( + startIndex !== undefined && endIndex !== undefined, + 'forEachKeyRange must be given keys that are present.' + ); if (endIndex < startIndex) { throw new Error(RANGE_ARGS); } diff --git a/src/utils/__tests__/OrderedMap-test.js b/src/utils/__tests__/OrderedMap-test.js index a65c996986..361142df24 100644 --- a/src/utils/__tests__/OrderedMap-test.js +++ b/src/utils/__tests__/OrderedMap-test.js @@ -739,10 +739,16 @@ describe('OrderedMap', function() { }).not.toThrow(); expect(function() { om.mapKeyRange(duplicate, 'x' , 3, scope); - }).not.toThrow(); + }).toThrow( + 'Invariant Violation: mapKeyRange must be given keys ' + + 'that are present.' + ); expect(function() { om.forEachKeyRange(duplicate, 'x', 3, scope); - }).not.toThrow(); + }).toThrow( + 'Invariant Violation: forEachKeyRange must be given keys ' + + 'that are present.' + ); expect(function() { om.mapRange(duplicate, 0, 4, scope);