
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
chai-moment
Advanced tools
Matchers for dates and formatted date strings powered by moment.js
Also see the tests and examples.
include chai moment after chai and moment:
<script src="moment.js"></script>
<script src="chai.js"></script>
<script src="chai-moment.js"></script>
have chai use chai-moment:
var chai = require('chai');
chai.use(require('chai-moment'));
Compare any moment-parseable date/string/whatever with another, with optional granularity. See Moment.js docs on parsing.
When using granularity, please use one of the following: year
, month
, week
, day
, hour
, minute
, second
. When using tdd-style assertions, if you do not use one of the listed granularities, the argument will be interpreted as a custom error message.
var dateString = '2016-04-21',
date = new Date(2016, 3, 21),
milliseconds = 1461222000000, // assumes system has PDT timezone
obj = { y: 2016, M: 3, d: 21 },
arr = [2016, 3, 21],
momentObj = moment('2016-04-21'),
oneDayLater = '2016-04-22';
// using should-style assertions
dateString.should.be.sameMoment(date);
dateString.should.be.sameMoment(oneDayLater, 'month');
// using expect-style assertions
expect(milliseconds).to.be.sameMoment(obj);
expect(dateString).to.be.sameMoment(oneDayLater, 'month');
// using tdd assertions
assert.sameMoment(arr, momentObj);
assert.sameMoment(arr, oneDayLater, 'month');
assert.sameMoment(arr, oneDayLater, 'month', 'custom error message');
assert.sameMoment(arr, oneDayLater, 'custom error message'); // fails
var dateString = '2016-04-21',
oneDayLater = '2016-04-22';
// using should-style assertions
dateString.should.be.beforeMoment(oneDayLater);
dateString.should.be.beforeMoment(oneDayLater, 'month'); // fails
// using expect-style assertions
expect(dateString).to.be.beforeMoment(oneDayLater);
expect(dateString).to.be.beforeMoment(oneDayLater, 'month'); // fails
// using tdd assertions
assert.beforeMoment(dateString, oneDayLater);
assert.beforeMoment(dateString, oneDayLater, 'month'); // fails
assert.beforeMoment(dateString, oneDayLater, 'month', 'custom error message'); // fails
assert.beforeMoment(dateString, oneDayLater, 'custom error message');
var dateString = '2016-04-21',
oneDayLater = '2016-04-22';
// using should-style assertions
oneDayLater.should.be.afterMoment(dateString);
oneDayLater.should.be.afterMoment(dateString, 'month'); // fails
// using expect-style assertions
expect(oneDayLater).to.be.afterMoment(dateString);
expect(oneDayLater).to.be.afterMoment(dateString, 'month'); // fails
// using tdd assertions
assert.afterMoment(oneDayLater, dateString);
assert.afterMoment(oneDayLater, dateString, 'month'); // fails
assert.afterMoment(oneDayLater, dateString, 'month', 'custom error message'); // fails
assert.afterMoment(oneDayLater, dateString, 'custom error message');
Sets the format used for reporting moments in failed assertions.
var chaiMoment = require('chai-moment');
chaiMoment.setErrorFormat('L');
expect(moment('2016-04-21')).to.be.beforeMoment(moment('2016-04-22'));
// Error('expected 04/21/2017 to be before 04/22/2016')
Thanks to chai-fuzzy for the project structure.
FAQs
date assertions for chai, powered by moment
The npm package chai-moment receives a total of 4,719 weekly downloads. As such, chai-moment popularity was classified as popular.
We found that chai-moment demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.