Skip to content

Single Jest unit test fails on local due to timezone

Summary

Unit test on spec/frontend/serverless/components/area_spec.js fails on my local.

$ yarn run jest
yarn run v1.15.2
$ BABEL_ENV=jest jest
 PASS  spec/frontend/clusters/components/applications_spec.js
 FAIL  spec/frontend/serverless/components/area_spec.js
  ● Area component › methods › formatTooltipText › series is of line type › formats tooltip title

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

    Expected: "28 Feb 2019, 11:11AM"
    Received: "28 Feb 2019, 7:11PM"

      52 | 
      53 |         it('formats tooltip title', () => {
    > 54 |           expect(areaChart.vm.tooltipPopoverTitle).toBe('28 Feb 2019, 11:11AM');
         |                                                    ^
      55 |         });
      56 | 
      57 |         it('formats tooltip content', () => {

      at Object.toBe (spec/frontend/serverless/components/area_spec.js:54:52)
...

Steps to reproduce

  • On a machine with a timezone different from UTC
  • Install Gitlab CE using GDK
  • Run yarn test locally

What is the current bug behavior?

Test Area component › methods › formatTooltipText › series is of line type › formats tooltip title fails

What is the expected correct behavior?

Test Area component › methods › formatTooltipText › series is of line type › formats tooltip title passed

Relevant logs and/or screenshots

N/A

Possible fixes

Related loc:

Forcing UTC to parse the date will allow the test to pass (but this would cause a bug!):

$ git diff app/
diff --git a/app/assets/javascripts/serverless/components/area.vue b/app/assets/javascripts/serverless/components/area.vue
index 32c9d6eccb8..5b9ba81735a 100644
--- a/app/assets/javascripts/serverless/components/area.vue
+++ b/app/assets/javascripts/serverless/components/area.vue
@@ -109,7 +109,7 @@ export default {
   methods: {
     formatTooltipText(params) {
       const [seriesData] = params.seriesData;
-      this.tooltipPopoverTitle = dateFormat(params.value, 'dd mmm yyyy, h:MMTT');
+      this.tooltipPopoverTitle = dateFormat(params.value, 'dd mmm yyyy, h:MMTT', true);
       this.tooltipPopoverContent = `${this.yAxisLabel}: ${seriesData.value[1]}`;
     },
     onResize() {

Note: I am not a serverless user/contributor, I simply ran jest after installing with GDK.

Edited by 🤖 GitLab Bot 🤖