2017-10-22 00:03:26 -05:00
|
|
|
import { configure } from 'enzyme';
|
2021-11-09 05:30:04 -06:00
|
|
|
import { EventBusSrv } from '@grafana/data';
|
2020-11-18 12:37:17 -06:00
|
|
|
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
2018-06-12 09:14:22 -05:00
|
|
|
import $ from 'jquery';
|
2020-02-17 04:13:13 -06:00
|
|
|
import 'mutationobserver-shim';
|
2019-11-07 05:37:46 -06:00
|
|
|
|
2021-11-09 05:30:04 -06:00
|
|
|
const testAppEvents = new EventBusSrv();
|
2019-11-07 05:37:46 -06:00
|
|
|
const global = window as any;
|
|
|
|
global.$ = global.jQuery = $;
|
|
|
|
|
2021-06-17 13:20:27 -05:00
|
|
|
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
|
|
|
Object.defineProperty(global, 'matchMedia', {
|
|
|
|
writable: true,
|
|
|
|
value: jest.fn().mockImplementation((query) => ({
|
|
|
|
matches: false,
|
|
|
|
media: query,
|
|
|
|
onchange: null,
|
|
|
|
addListener: jest.fn(), // deprecated
|
|
|
|
removeListener: jest.fn(), // deprecated
|
|
|
|
addEventListener: jest.fn(),
|
|
|
|
removeEventListener: jest.fn(),
|
|
|
|
dispatchEvent: jest.fn(),
|
|
|
|
})),
|
|
|
|
});
|
|
|
|
|
2019-11-07 05:37:46 -06:00
|
|
|
import '../vendor/flot/jquery.flot';
|
|
|
|
import '../vendor/flot/jquery.flot.time';
|
2018-06-12 09:14:22 -05:00
|
|
|
import angular from 'angular';
|
|
|
|
|
|
|
|
angular.module('grafana', ['ngRoute']);
|
|
|
|
angular.module('grafana.services', ['ngRoute', '$strap.directives']);
|
|
|
|
angular.module('grafana.panels', []);
|
|
|
|
angular.module('grafana.controllers', []);
|
|
|
|
angular.module('grafana.directives', []);
|
|
|
|
angular.module('grafana.filters', []);
|
|
|
|
angular.module('grafana.routes', ['ngRoute']);
|
|
|
|
|
2021-11-09 05:30:04 -06:00
|
|
|
jest.mock('../app/core/core', () => ({ appEvents: testAppEvents }));
|
2021-10-27 08:21:07 -05:00
|
|
|
jest.mock('../app/angular/partials', () => ({}));
|
|
|
|
jest.mock('../app/features/plugins/plugin_loader', () => ({}));
|
2017-10-22 00:03:26 -05:00
|
|
|
|
|
|
|
configure({ adapter: new Adapter() });
|
2018-06-12 09:14:22 -05:00
|
|
|
|
2018-09-07 10:55:38 -05:00
|
|
|
const localStorageMock = (() => {
|
2019-06-19 12:59:03 -05:00
|
|
|
let store: any = {};
|
2018-09-02 12:36:36 -05:00
|
|
|
return {
|
2019-04-03 04:41:08 -05:00
|
|
|
getItem: (key: string) => {
|
2018-09-02 12:36:36 -05:00
|
|
|
return store[key];
|
|
|
|
},
|
2019-06-19 12:59:03 -05:00
|
|
|
setItem: (key: string, value: any) => {
|
2018-09-02 12:36:36 -05:00
|
|
|
store[key] = value.toString();
|
|
|
|
},
|
2018-09-07 10:55:38 -05:00
|
|
|
clear: () => {
|
2018-09-02 12:36:36 -05:00
|
|
|
store = {};
|
|
|
|
},
|
2019-04-03 04:41:08 -05:00
|
|
|
removeItem: (key: string) => {
|
2018-09-02 12:36:36 -05:00
|
|
|
delete store[key];
|
|
|
|
},
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
global.localStorage = localStorageMock;
|
2019-10-04 05:01:42 -05:00
|
|
|
|
2019-09-25 07:10:11 -05:00
|
|
|
const throwUnhandledRejections = () => {
|
2021-01-20 00:59:48 -06:00
|
|
|
process.on('unhandledRejection', (err) => {
|
2019-09-25 07:10:11 -05:00
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
throwUnhandledRejections();
|