unadlib / mutative

Efficient immutable updates, 2-6x faster than naive handcrafted reducer, and more than 10x faster than Immer.
http://mutative.js.org/
MIT License
1.58k stars 18 forks source link

test(test): fix inconsistent timezone in date tests #40

Closed dabbott closed 4 months ago

dabbott commented 4 months ago

I noticed a few date-related tests weren't passing for me locally:

 FAIL  test/unsafe.test.ts
  ● change Date instance

    expect(received).toBe(expected) // Object.is equality

    Expected: 946684800000
    Received: 946627200000

      577 |   expect(data.foo).toBe(state.foo);
      578 |   expect(data.date).toBe(state.date);
    > 579 |   expect(state.date.getTime()).toBe(946684800000);
          |                                ^
      580 | });
      581 |

      at Object.<anonymous> (test/unsafe.test.ts:579:32)

I believe this is because setFullYear applies the system's local time zone automatically. Using setMilliseconds should avoid this issue. With this change, all tests pass locally and presumably shouldn't impact the github actions test runner.

I love the library and I'm excited to start poking around the code more!