chai-moment-string

chai plugin for validating a string with an expected moment format

Build Status Downloads

Usage

Browser

<script src="chai.js"></script>
<script src="chai-moment-string.js"></script>

Server

var chai = require('chai');
chai.use(require('chai-moment-string'));

Assertions

  • momentFormat
  • strict(chained by momentFormat)

momentFormat

// Without locale
expect('2018-01-26').to.momentFormat('YYYY-MM-DD');
// With locale
expect('2012 juillet').to.momentFormat('YYYY MMMM', 'fr');

strict

// Without locale
expect('2018-01-26').to.momentFormat.strict('YYYY-MM-DD');
// With locale
expect('2012 juillet').to.momentFormat.strict('YYYY MMMM', 'fr');

See more for the strict parsing: https://momentjs.com/guides/#/parsing/strict-mode/