mengxiong10 / vue2-datepicker

A datepicker / datetimepicker component for Vue2
https://mengxiong10.github.io/vue2-datepicker/index.html
MIT License
1.52k stars 405 forks source link

Test suites fail when run from another timezone #300

Closed marcofiset closed 5 years ago

marcofiset commented 5 years ago

I'm located in Canada and tests fail when I run them.

I change my timezone to China, run the tests again, now everything passes.

Tests should pass no matter what timezone I'm located in.

mengxiong10 commented 5 years ago

Which test is failed? What's the error?

marcofiset commented 5 years ago

Here you go (I'm located in GMT-4) :

 PASS  test\language.spec.js
 PASS  test\transform.spec.js
 FAIL  test\index.spec.js (9.335s)
  ● Console

    console.error node_modules\vue\dist\vue.runtime.common.js:589
      [Vue warn]: Error in nextTick: "Error: expect(received).toEqual(expected)

      Expected value to equal:
        [2019-05-11T04:00:00.000Z, 2019-05-13T04:00:00.000Z]
      Received:
        [2019-05-12T04:00:00.000Z, 2019-05-14T04:00:00.000Z]

      Difference:

      - Expected
      + Received

        Array [
      -   2019-05-11T04:00:00.000Z,
      -   2019-05-13T04:00:00.000Z,
      +   2019-05-12T04:00:00.000Z,
      +   2019-05-14T04:00:00.000Z,
        ]"
    console.error node_modules\vue\dist\vue.runtime.common.js:1739
      { Error: expect(received).toEqual(expected)

      Expected value to equal:
        [2019-05-11T04:00:00.000Z, 2019-05-13T04:00:00.000Z]
      Received:
        [2019-05-12T04:00:00.000Z, 2019-05-14T04:00:00.000Z]

      Difference:

      - Expected
      + Received

        Array [
      -   2019-05-11T04:00:00.000Z,
      -   2019-05-13T04:00:00.000Z,
      +   2019-05-12T04:00:00.000Z,
      +   2019-05-14T04:00:00.000Z,
        ]
          at C:\code\marco\vue2-datepicker\test\index.spec.js:154:37
          at Array.<anonymous> (C:\code\marco\vue2-datepicker\node_modules\vue\dist\vue.runtime.common.js:1835:12)
          at flushCallbacks (C:\code\marco\vue2-datepicker\node_modules\vue\dist\vue.runtime.common.js:1756:14)
          at Timeout.callback [as _onTimeout] (C:\code\marco\vue2-datepicker\node_modules\jsdom\lib\jsdom\browser\Window.js:628:19)
          at ontimeout (timers.js:469:11)
          at tryOnTimeout (timers.js:304:5)
          at Timer.listOnTimeout (timers.js:264:5)
        matcherResult:
         { actual: [ 2019-05-12T04:00:00.000Z, 2019-05-14T04:00:00.000Z ],
           expected: [ 2019-05-11T04:00:00.000Z, 2019-05-13T04:00:00.000Z ],
           message: [Function],
           name: 'toEqual',
           pass: false } }

  ● datepicker › prop: range

    Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

      116 |   })
      117 |
    > 118 |   it('prop: range', (done) => {
          |   ^
      119 |     wrapper = mount(DatePicker, {
      120 |       propsData: {
      121 |         range: true,

      at new Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:85:20)
      at Suite.<anonymous> (test/index.spec.js:118:3)
      at Object.<anonymous> (test/index.spec.js:16:1)

  ● datepicker › prop: rangeSeparator

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

    Expected: "2018-06-01 至 2018-06-10"
    Received: "2018-05-31 至 2018-06-09"

      167 |     })
      168 |     const vm = wrapper.vm
    > 169 |     expect(vm.text).toBe('2018-06-01 至 2018-06-10')
          |                     ^
      170 |   })
      171 |
      172 |   it('prop: confirm', () => {

      at Object.<anonymous> (test/index.spec.js:169:21)

  ● datepicker › prop: dateFormat

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

    Expected: "08-08-2018"
    Received: "08-07-2018"

      369 |     const cell = wrapper.find('.mx-panel-date .actived')
      370 |     const timeHeader = wrapper.find('.mx-time-header')
    > 371 |     expect(cell.element.title).toBe(ss)
          |                                ^
      372 |     expect(timeHeader.text()).toBe(ss)
      373 |     wrapper.setProps({
      374 |       dateFormat: 'YYYY-MM-DD'

      at Object.<anonymous> (test/index.spec.js:371:32)

  ● calendar-panel › prop: defaultValue

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

    Expected: 9
    Received: 8

      390 |     const vm = wrapper.vm
      391 |     expect(vm.calendarYear).toBe(2018)
    > 392 |     expect(vm.calendarMonth).toBe(9)
          |                              ^
      393 |   })
      394 |
      395 |   it('click: prev/next month', () => {

      at Object.<anonymous> (test/index.spec.js:392:30)

  ● calendar-panel › prop: disabledDays(Array)

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

    Expected: 1525060800000
    Received: 1524974400000

      513 |       const tdDate = new Date(tds.at(i).element.title).setHours(0, 0, 0, 0)
      514 |       const expectDate = new Date(disabledDays[i]).setHours(0, 0, 0, 0)
    > 515 |       expect(tdDate).toBe(expectDate)
          |                      ^
      516 |     }
      517 |   })
      518 |

      at Object.<anonymous> (test/index.spec.js:515:22)

Test Suites: 1 failed, 2 passed, 3 total
Tests:       5 failed, 48 passed, 53 total
Snapshots:   0 total
Time:        11.28s
Ran all test suites.
marcofiset commented 5 years ago

And here's what happens when I change my timezone to GMT+8.

 PASS  test\transform.spec.js
 PASS  test\language.spec.js
 PASS  test\index.spec.js

Test Suites: 3 passed, 3 total
Tests:       53 passed, 53 total
Snapshots:   0 total
Time:        4.209s, estimated 10s
Ran all test suites.
mengxiong10 commented 5 years ago

v2.11.2 fixed it.