Repository: date-fns/date-fns
File: src/set/test.js (JavaScript)

Code before:
    assert.deepEqual(result, new Date(2014, 8))
  })
  it('test only month', function() {
    var result = set(new Date(2014, 8 /* Sep */), { month: 9 })
    assert.deepEqual(result, new Date(2014, 9 /* Oct */))
  })
  it('test only date', function() {
    var result = set(new Date(2014, 8), { date: 20 })
    assert.deepEqual(result, new Date(2014, 8, 20))
  })
  it('test month in January', function() {
    var result = set(new Date(2014, 8 /* Sep */), { month: 0 })
    assert.deepEqual(result, new Date(2014, 0 /* Jan */))
  })
  it('test only hours', function() {
    var result = set(new Date(2014, 8, 1), { hours: 12 })
    assert.deepEqual(result, new Date(2014, 8, 1, 12))
  })
  it('test only minutes', function() {
    var result = set(new Date(2014, 8, 1, 1), { minutes: 12 })
    assert.deepEqual(result, new Date(2014, 8, 1, 1, 12))
  })
  it('test only seconds', function() {
    var result = set(new Date(2014, 8, 1, 1, 1), { seconds: 12 })
    assert.deepEqual(result, new Date(2014, 8, 1, 1, 1, 12))
  })
  it('test only milliseconds', function() {
    var result = set(new Date(2014, 8, 1, 1, 1, 1), { milliseconds: 500 })
    assert.deepEqual(result, new Date(2014, 8, 1, 1, 1, 1, 500))
  })
  it('month turns into year', function() {
    var result = set(new Date(2014, 8), { month: 13 })
    assert.deepEqual(result, new Date(2015, 1))
  })
  it('date turns into month', function() {
    var result = set(new Date(2014, 8), { date: 31 })
    assert.deepEqual(result, new Date(2014, 9))
  })
  it('hours turns into date', function() {
    var result = set(new Date(2014, 8, 19), { hours: 24 })
    assert.deepEqual(result, new Date(2014, 8, 20))
  })
  it('minutes turns into hours', function() {
    var result = set(new Date(2014, 8, 20, 11), { minutes: 60 })
    assert.deepEqual(result, new Date(2014, 8, 20, 12))
  })
  it('seconds turns into minutes', function() {
    var result = set(new Date(2014, 8, 20, 12, 58), { seconds: 60 })
    assert.deepEqual(result, new Date(2014, 8, 20, 12, 59))
  })
  it('milliseconds turns into seconds', function() {

Review comment (bug):
Please add edge case tests:
1. for when any value in `values` is NaN (the result should be NaN)
2. for when any value in `values` is undefined (the value should be ignored)
3. for when any value in `values` is null (the value should be ignored)
4. for when any value in `values` is out of boundaries: day 32, month 12 and so on (the 32nd day should overflow into the next month, like native `Date#setDate`)
5. for when `value` is not an object (`RangeError`)

Code after:
  })

  it('sets year', function() {
    var result = set(new Date(2013, 8 /* Sep */), { year: 2014 })
    assert.deepEqual(result, new Date(2014, 8 /* Sep */))
  })

  it('sets month', function() {
    var result = set(new Date(2014, 8 /* Sep */), { month: 9 /* Oct */ })
    assert.deepEqual(result, new Date(2014, 9 /* Oct */))
  })

  it('sets day of month', function() {
    var result = set(new Date(2014, 8 /* Sep */), { date: 20 })
    assert.deepEqual(result, new Date(2014, 8 /* Sep */, 20))
  })

  it('sets hours', function() {
    var result = set(new Date(2014, 8 /* Sep */, 1), { hours: 12 })
    assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 12))
  })

  it('sets minutes', function() {
    var result = set(new Date(2014, 8 /* Sep */, 1, 1), { minutes: 12 })
    assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 1, 12))
  })

  it('sets seconds', function() {
    var result = set(new Date(2014, 8 /* Sep */, 1, 1, 1), { seconds: 12 })
    assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 1, 1, 12))
  })

  it('sets milliseconds', function() {
    var result = set(new Date(2014, 8 /* Sep */, 1, 1, 1, 1), {
      milliseconds: 500
    })
    assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 1, 1, 1, 500))
  })

  describe('value overflow', function() {
    it('months overflow into years', function() {
      var result = set(new Date(2014, 8 /* Sep */, 1), {
        month: 12 /* 13th month */
      })
      assert.deepEqual(result, new Date(2015, 0 /* Jan */, 1))
    })

    it('days of months overflow into months', function() {
      var result = set(new Date(2014, 8 /* Sep */, 1), { date: 31 })
      assert.deepEqual(result, new Date(2014, 9 /* Oct */, 1))
    })