Skip to content

Commit

Permalink
Fixed issue with findObjs(). It was returning undefined instead of an…
Browse files Browse the repository at this point in the history
… empty array if nothing was found.
  • Loading branch information
kyleady committed Oct 13, 2017
1 parent 0538d25 commit edc178d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Functions/API_Objects/FindObjs.js
Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions test/Functions/API_Objects/FindObjs.js
Expand Up @@ -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});
Expand All @@ -43,4 +49,5 @@ describe('findObjs()', function(){
it('should return every object if given invalid attributes', function(){
expect(findObjs().length).to.equal(getAllObjs().length);
});

});

0 comments on commit edc178d

Please sign in to comment.