Skip to content

najs-framework/mongoose-timestamps-moment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

npm install -s mongoose-timestamps-moment moment

Usage

Replacing setupTimestamp in mongoose Schema.prototype

Schema.prototype.setupTimestamp = require('mongoose-timestamps-moment').setupTimestamp

After that you can set custom now value in unit test

const Moment = require('moment')

describe('Custom "now" value', function() {
  it('can create in a specific date', async function() {
    const now = new Date(1988, 4, 16)
    Moment.now = () => now

    const model = new Model()
    await model.save()
    expect(model.createdAt).toEqual(now)
    expect(model.updatedAt).toEqual(now)
  })
})

License

MIT @ Nhat Phan

About

Replacing mongoose timestamps options use moment instead of native Date function.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published