to satisfy

  • <moment> to satisfy <moment|string|number|date|array|object>

Passes if one moment instance represents the same time as another time instance.

var date = moment();
expect(moment('2015-11-01'), 'to satisfy', '2015-11-01');

Unlike to-equal, you can check against any object that represents an instance of time, as supported by moment#isSame:

expect(moment('2015-11-01'), 'to satisfy', { year: 2015, month: 10, day: 1 });

When the assertion fails you'll get this output:

expect(moment('2015-11-01'), 'to satisfy', { year: 2015, month: 11, day: 1 });
expected moment('2015-11-01T00:00:00.000+01:00')
to satisfy { year2015month11day1 }
 
moment(
  
{
  
year2015,
  
month
10,
 
//
 
should equal 
11
  
day1
}
)

Variations with moment#isSame

There are some subtle differences with moment#isSame that you should be aware of:

  • Empty arrays are not deemed as valid values
  • Empty objects are not deemed as valid values
  • Objects with invalid units are also deemed as invalid
expect(function () {
    expect(moment(), 'to satisfy', []);
}, 'to error'); // even though moment().isSame([]) === true
expect(function () {
    expect(moment(), 'to satisfy', {});
}, 'to error'); // even though moment().isSame({}) === true
var theMoment = moment('2016-08-03');
var theObject = { year: 2016, month: 7, date: 3, minyte: 4, second: 0, millisecond: 0 };
// this fails even though theMoment.isSame(theObject) === true
expect(theMoment, 'to satisfy', theObject);
expected moment('2016-08-03T00:00:00.000+02:00')
to satisfy { year2016month7date3minyte4second0millisecond0 }
 
moment(
  
{
  year2016,
  month7,
  date3,
  minyte4
//
 
not a valid unit
  second0,
  millisecond0
}
)

This is aimed at giving you more confidence in your tests.