jest-setup.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { configure } from 'enzyme';
  2. import Adapter from 'enzyme-adapter-react-16';
  3. import 'jquery';
  4. import $ from 'jquery';
  5. import 'angular';
  6. import angular from 'angular';
  7. angular.module('grafana', ['ngRoute']);
  8. angular.module('grafana.services', ['ngRoute', '$strap.directives']);
  9. angular.module('grafana.panels', []);
  10. angular.module('grafana.controllers', []);
  11. angular.module('grafana.directives', []);
  12. angular.module('grafana.filters', []);
  13. angular.module('grafana.routes', ['ngRoute']);
  14. jest.mock('app/core/core', () => ({}));
  15. jest.mock('app/features/plugins/plugin_loader', () => ({}));
  16. configure({ adapter: new Adapter() });
  17. const global = window as any;
  18. global.$ = global.jQuery = $;
  19. const localStorageMock = (() => {
  20. let store = {};
  21. return {
  22. getItem: key => {
  23. return store[key];
  24. },
  25. setItem: (key, value) => {
  26. store[key] = value.toString();
  27. },
  28. clear: () => {
  29. store = {};
  30. },
  31. removeItem: key => {
  32. delete store[key];
  33. },
  34. };
  35. })();
  36. global.localStorage = localStorageMock;
  37. // Object.defineProperty(window, 'localStorage', { value: localStorageMock });