Skip to content

Commit 8c16354

Browse files
committed
test(query): repro #7152
1 parent 867391d commit 8c16354

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

test/model.findOneAndUpdate.test.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,14 +1655,29 @@ describe('model: findOneAndUpdate:', function() {
16551655
});
16561656
});
16571657

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

16611664
const Model = db.model('gh4136', modelSchema);
1662-
Model.find({ nonexistingField: 1 }).exec(function(error) {
1663-
assert.ok(error);
1664-
assert.ok(error.message.indexOf('strictQuery') !== -1, error.message);
1665-
done();
1665+
1666+
return co(function*() {
1667+
// `find()` on a top-level path not in the schema
1668+
let err = yield Model.find({ notInschema: 1 }).then(() => null, e => e);
1669+
assert.ok(err);
1670+
assert.ok(err.message.indexOf('strictQuery') !== -1, err.message);
1671+
1672+
// Shouldn't throw on nested path re: gh-7152
1673+
yield Model.create({ nested: { path: 'a' } });
1674+
const doc = yield Model.findOne({ nested: { path: 'a' } });
1675+
assert.ok(doc);
1676+
1677+
// `find()` on a nested path not in the schema
1678+
err = yield Model.find({ 'nested.bad': 'foo' }).then(() => null, e => e);
1679+
assert.ok(err);
1680+
assert.ok(err.message.indexOf('strictQuery') !== -1, err.message);
16661681
});
16671682
});
16681683

0 commit comments

Comments
 (0)