| 153 | } |
| 154 | |
| 155 | async function createWithMapOfSubdocs() { |
| 156 | const schema = new Schema({ |
| 157 | name: String, |
| 158 | subdocMap: { |
| 159 | type: Map, |
| 160 | of: new Schema({ prop: { type: String, required: true } }) |
| 161 | } |
| 162 | }); |
| 163 | const TestModel = model('Test', schema); |
| 164 | |
| 165 | const doc = await TestModel.create({ name: 'test', subdocMap: { taco: { prop: 'beef' } } }); |
| 166 | expect(doc.name).type.toBe<string | null | undefined>(); |
| 167 | expect(doc.subdocMap!.get('taco')!.prop).type.toBe<string>(); |
| 168 | |
| 169 | const doc2 = await TestModel.create({ name: 'test', subdocMap: [['taco', { prop: 'beef' }]] }); |
| 170 | expect(doc2.name).type.toBe<string | null | undefined>(); |
| 171 | expect(doc2.subdocMap!.get('taco')!.prop).type.toBe<string>(); |
| 172 | } |
| 173 | |
| 174 | async function createWithSubdocs() { |
| 175 | const schema = new Schema({ |