Skip to content

Commit

Permalink
Fix NPE for 'cannot read dryrun of undefined' (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuffant21 authored Aug 3, 2021
1 parent 9cc5240 commit acac3ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function _sanitize(target, options) {
};
}

function sanitize(target, options) {
function sanitize(target, options = {}) {
return _sanitize(target, options).target;
}

Expand Down
26 changes: 26 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,4 +979,30 @@ describe('Express Mongo Sanitize', function () {
);
});
});

describe('sanitize', function () {
it('should not throw a NPE when options is not passed into the function', function () {
const req = {
body: {
hello: 'world',
},
};

const resp = sanitize.sanitize(req.body);

expect(resp).to.deep.equal(req.body);
});

it('should return successfully with option passed in', function () {
const req = {
body: {
hello: 'world',
},
};

const resp = sanitize.sanitize(req.body, { dryRun: true });

expect(resp).to.deep.equal(req.body);
});
});
});

0 comments on commit acac3ef

Please sign in to comment.