Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Nov 16, 2020
1 parent 88f9a12 commit 417b0a4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { renderWithRouter, shallowWithRouter } from '../../../../lib';
import * as redux from 'react-redux';
import moment from 'moment';
import { IHttpFetchError } from '../../../../../../../../src/core/public';
import { mockMoment } from '../../../../lib/helper/testHelpers';

jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => {
return {
Expand Down Expand Up @@ -107,6 +108,10 @@ const testBarSummary: MonitorSummary = {
describe('MonitorList component', () => {
let localStorageMock: any;

beforeAll(() => {
mockMoment();
});

const getMonitorList = (timestamp?: string): MonitorSummariesResult => {
if (timestamp) {
testBarSummary.state.timestamp = timestamp;
Expand Down
22 changes: 22 additions & 0 deletions x-pack/plugins/uptime/public/lib/helper/test_helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

/* global jest */

import moment from 'moment';
import { Moment } from 'moment-timezone';

export function mockMoment() {
// avoid timezone issues
jest.spyOn(moment.prototype, 'format').mockImplementation(function (this: Moment) {
return `Sept 4, 2020 9:31:38 AM`;
});

// convert relative time to absolute time to avoid timing issues
jest.spyOn(moment.prototype, 'fromNow').mockImplementation(function (this: Moment) {
return `15 minutes ago`;
});
}
1 change: 0 additions & 1 deletion x-pack/plugins/uptime/public/pages/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import styled from 'styled-components';
import { i18n } from '@kbn/i18n';
import { useDispatch } from 'react-redux';
import { useGetUrlParams } from '../hooks';
import { stringifyUrlParams } from '../lib/helper/stringify_url_params';
import { PageHeader } from './page_header';
import { IIndexPattern } from '../../../../../src/plugins/data/public';
import { useUpdateKueryString } from '../hooks';
Expand Down

0 comments on commit 417b0a4

Please sign in to comment.