chunk-date-range icon indicating copy to clipboard operation
chunk-date-range copied to clipboard

months testing seems to be invalid

Open nmccready opened this issue 7 years ago • 2 comments

var assert = require('assert');
var chunk = require('./');
var Dates = require('date-math');

const getDay = (time, isString) => time.getDate();

const fromDays = days =>
  new Date(new Date()
    .setDate(getDay(new Date()) - days));

describe('chunk-date-range', function() {

  describe('by duration', function() {
    describe('month', () => {
      const duration = 'month';
      it('31 days is 1', () => {
        const start = fromDays(31);
        console.log({ start });
        const chunks = chunk(start, new Date(), duration);
        assert.equal(chunks.length, 1);
      });
      it('32 days is 2', () => { // FAILS with 1 chunk
        const start = fromDays(32);
        console.log({ start });
        const chunks = chunk(start, new Date(), duration);
        assert.equal(chunks.length, 2);
      });
    });
  });

  function verify(chunks, start, end) {
    assert.equal(+chunks[0].start, +start);
    assert.equal(+chunks[chunks.length - 1].end, +end);
    chunks.forEach(function(chunk, i) {
      var next = chunks[i + 1];
      if (!next) return;
      assert.equal(+chunk.end, +next.start);
    });
  }
});

nmccready avatar Apr 13 '18 19:04 nmccready

Ok, fixed the test showing possible problems.

nmccready avatar Apr 13 '18 20:04 nmccready

See #2

nmccready avatar Apr 13 '18 21:04 nmccready