Skip to content

Commit acac3ef

Browse files
authored
Fix NPE for 'cannot read dryrun of undefined' (#88)
1 parent 9cc5240 commit acac3ef

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function _sanitize(target, options) {
8787
};
8888
}
8989

90-
function sanitize(target, options) {
90+
function sanitize(target, options = {}) {
9191
return _sanitize(target, options).target;
9292
}
9393

test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,4 +979,30 @@ describe('Express Mongo Sanitize', function () {
979979
);
980980
});
981981
});
982+
983+
describe('sanitize', function () {
984+
it('should not throw a NPE when options is not passed into the function', function () {
985+
const req = {
986+
body: {
987+
hello: 'world',
988+
},
989+
};
990+
991+
const resp = sanitize.sanitize(req.body);
992+
993+
expect(resp).to.deep.equal(req.body);
994+
});
995+
996+
it('should return successfully with option passed in', function () {
997+
const req = {
998+
body: {
999+
hello: 'world',
1000+
},
1001+
};
1002+
1003+
const resp = sanitize.sanitize(req.body, { dryRun: true });
1004+
1005+
expect(resp).to.deep.equal(req.body);
1006+
});
1007+
});
9821008
});

0 commit comments

Comments
 (0)