Skip to content

Commit

Permalink
contacts.find with null or empty array args should fire error callbac…
Browse files Browse the repository at this point in the history
…k. tests + fix
  • Loading branch information
Fil Maj committed Feb 15, 2012
1 parent a3da79c commit bf37bd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/plugin/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var contacts = {
if (!successCB) {
throw new TypeError("You must specify a success callback for the find command.");
}
if (!fields) {
if (!fields || (fields instanceof Array && fields.length === 0)) {
if (typeof errorCB === "function") {
errorCB(new ContactError(ContactError.INVALID_ARGUMENT_ERROR));
}
Expand Down
8 changes: 7 additions & 1 deletion test/test.contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ describe("contacts", function () {
expect(contacts.find).toThrow("You must specify a success callback for the find command.");
});

it("doesn't call exec with no fields", function () {
it("doesn't call exec with null fields", function () {
exec.reset();
contacts.find(null, jasmine.createSpy());
expect(exec).not.toHaveBeenCalled();
});

it("doesn't call exec with empty fields", function () {
exec.reset();
contacts.find([], jasmine.createSpy());
expect(exec).not.toHaveBeenCalled();
});

it("calls the error callback when no fields provied", function () {
var success = jasmine.createSpy(),
error = jasmine.createSpy();
Expand Down

0 comments on commit bf37bd3

Please sign in to comment.