Skip to content

Commit

Permalink
feat: add test for check the default value of the schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Barrior committed Oct 21, 2019
1 parent 746701f commit 553b074
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/check-default-value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import moment from 'moment'
import mongoose from 'mongoose'
import modifiedAt from '~/index'
import './@helpers/connect-db'
import { isDateTypeAndValueValid, randomName } from './@helpers/utils'

test('Default value of Schema is not support', async () => {
const schema = new mongoose.Schema({
name: String,
age: {
type: Number,
default: 1,
},
})

schema.plugin(modifiedAt, ['name', 'age'])

const Cat = mongoose.model(randomName(), schema)
const startTime = moment()
const kitty: any = await Cat.create({ name: 'Kitty' })

expect(kitty.name).toBe('Kitty')
expect(kitty.age).toBe(1)
expect(kitty.age_modifiedAt).toBeUndefined()
isDateTypeAndValueValid(kitty.name_modifiedAt, { startTime })
})

0 comments on commit 553b074

Please sign in to comment.