Skip to content

Commit

Permalink
test(query): repro #7152
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Oct 31, 2018
1 parent 867391d commit 8c16354
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions test/model.findOneAndUpdate.test.js
Expand Up @@ -1655,14 +1655,29 @@ describe('model: findOneAndUpdate:', function() {
});
});

it('strictQuery option (gh-4136)', function(done) {
const modelSchema = new Schema({ field: Number }, { strictQuery: 'throw' });
it('strictQuery option (gh-4136) (gh-7152)', function() {
const modelSchema = new Schema({
field: Number,
nested: { path: String }
}, { strictQuery: 'throw' });

const Model = db.model('gh4136', modelSchema);
Model.find({ nonexistingField: 1 }).exec(function(error) {
assert.ok(error);
assert.ok(error.message.indexOf('strictQuery') !== -1, error.message);
done();

return co(function*() {
// `find()` on a top-level path not in the schema
let err = yield Model.find({ notInschema: 1 }).then(() => null, e => e);
assert.ok(err);
assert.ok(err.message.indexOf('strictQuery') !== -1, err.message);

// Shouldn't throw on nested path re: gh-7152
yield Model.create({ nested: { path: 'a' } });
const doc = yield Model.findOne({ nested: { path: 'a' } });
assert.ok(doc);

// `find()` on a nested path not in the schema
err = yield Model.find({ 'nested.bad': 'foo' }).then(() => null, e => e);
assert.ok(err);
assert.ok(err.message.indexOf('strictQuery') !== -1, err.message);
});
});

Expand Down

0 comments on commit 8c16354

Please sign in to comment.