chai-moment-string
Chai 插件,用于验证字符串是否符合预期的 Moment 格式
使用
浏览器
<script src="chai.js"></script>
<script src="chai-moment-string.js"></script>
服务器
var chai = require('chai');
chai.use(require('chai-moment-string'));
断言
- momentFormat
- strict(由 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');
有关严格解析的更多信息,请参阅:https://moment.js.cn/guides/#/parsing/strict-mode/