| 14956 | it('calls required with correct context on single nested properties (gh-14788)', async function() { |
| 14957 | const requiredCalls = []; |
| 14958 | function createCustomSchema() { |
| 14959 | return new mongoose.Schema({ |
| 14960 | prop1: { |
| 14961 | type: String, |
| 14962 | required() { |
| 14963 | requiredCalls.push(this); |
| 14964 | return this.prop1 === undefined; |
| 14965 | }, |
| 14966 | validate: { |
| 14967 | validator(prop1) { |
| 14968 | if (this.prop2 !== null && prop1 != null) { |
| 14969 | throw new Error('cannot use prop1 if prop2 is defined!'); |
| 14970 | } |
| 14971 | return true; |
| 14972 | } |
| 14973 | } |
| 14974 | }, |
| 14975 | prop2: { |
| 14976 | type: String, |
| 14977 | required() { |
| 14978 | requiredCalls.push(this); |
| 14979 | return this.prop2 === undefined; |
| 14980 | }, |
| 14981 | validate: { |
| 14982 | validator(prop2) { |
| 14983 | if (this.prop1 === null && prop2 === null) { |
| 14984 | throw new Error('cannot be null if prop1 is missing!'); |
| 14985 | } |
| 14986 | return true; |
| 14987 | } |
| 14988 | } |
| 14989 | } |
| 14990 | }, { _id: false }); |
| 14991 | } |
| 14992 | |
| 14993 | const schema = new mongoose.Schema({ |
| 14994 | config: { |