From edc178d937782c97c30a2e63cd6c15c1d2fe1fb1 Mon Sep 17 00:00:00 2001 From: Kyle Ady Date: Fri, 13 Oct 2017 13:51:51 -0700 Subject: [PATCH] Fixed issue with findObjs(). It was returning undefined instead of an empty array if nothing was found. --- Functions/API_Objects/FindObjs.js | 2 +- test/Functions/API_Objects/FindObjs.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Functions/API_Objects/FindObjs.js b/Functions/API_Objects/FindObjs.js index 2e5b139..7890282 100644 --- a/Functions/API_Objects/FindObjs.js +++ b/Functions/API_Objects/FindObjs.js @@ -18,7 +18,7 @@ module.exports = function (attrs, options) { }; var types = {}; if (attrs._type) { - if (Bank[attrs._type] == undefined) return undefined; + if (Bank[attrs._type] == undefined) return []; types[attrs._type] = true; } else { for (var type in Bank) { diff --git a/test/Functions/API_Objects/FindObjs.js b/test/Functions/API_Objects/FindObjs.js index daadc85..b0744c3 100644 --- a/test/Functions/API_Objects/FindObjs.js +++ b/test/Functions/API_Objects/FindObjs.js @@ -28,8 +28,14 @@ describe('findObjs()', function(){ expect(foundObjs).to.include.members([handout, macro, character]); expect(foundObjs).to.not.include(dontFindMe); }); - it('should return undefined if you try to search an invalid type', function(){ - expect(findObjs({_type: 'not actually a type'})).to.be.undefined; + + it('should return an empty array if there is no matching objs', function(){ + expect(findObjs({_type: 'attribute', name: 'this is not an existing attribute'})).to.be.an('array'); + expect(findObjs({_type: 'attribute', name: 'this is not an existing attribute'})).to.be.empty; + }); + it('should return an empty array if you try to search an invalid type', function(){ + expect(findObjs({_type: 'not actually a type'})).to.be.an('array'); + expect(findObjs({_type: 'not actually a type'})).to.be.empty; }); it('should properly find objects created by createObj(), including folders, when using a MOCK20override', function(){ var playlist = createObj('playlist', {n: "find me!"}, {MOCK20override: true}); @@ -43,4 +49,5 @@ describe('findObjs()', function(){ it('should return every object if given invalid attributes', function(){ expect(findObjs().length).to.equal(getAllObjs().length); }); + });