index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. import Chart from 'chart.js';
  3. import fixture from './fixture';
  4. import matchers from './matchers';
  5. import utils from './utils';
  6. var charts = {};
  7. jasmine.chart = {
  8. acquire: function() {
  9. var chart = utils.acquireChart.apply(utils, arguments);
  10. charts[chart.id] = chart;
  11. return chart;
  12. },
  13. release: function(chart) {
  14. utils.releaseChart.apply(utils, arguments);
  15. delete charts[chart.id];
  16. }
  17. };
  18. jasmine.fixture = fixture;
  19. jasmine.triggerMouseEvent = utils.triggerMouseEvent;
  20. beforeEach(function() {
  21. jasmine.addMatchers(matchers);
  22. Chart.helpers.merge(Chart.defaults.global, {
  23. animation: false,
  24. legend: {display: false},
  25. responsive: false,
  26. title: {display: false},
  27. tooltips: false,
  28. elements: {
  29. arc: {
  30. backgroundColor: 'transparent',
  31. borderColor: 'rgba(0, 0, 0, 0.1)',
  32. borderWidth: 1
  33. },
  34. point: {
  35. backgroundColor: 'transparent',
  36. borderColor: 'rgba(0, 0, 0, 0.1)',
  37. borderWidth: 1
  38. },
  39. rectangle: {
  40. backgroundColor: 'transparent',
  41. borderColor: 'rgba(0, 0, 0, 0.1)',
  42. borderWidth: 1
  43. }
  44. }
  45. });
  46. Chart.helpers.merge(Chart.defaults.scale, {
  47. display: false,
  48. ticks: {
  49. beginAtZero: true
  50. }
  51. });
  52. });
  53. afterEach(function() {
  54. // Auto releasing acquired charts
  55. Object.keys(charts).forEach(function(id) {
  56. var chart = charts[id];
  57. if (!(chart.$test || {}).persistent) {
  58. jasmine.chart.release(chart);
  59. }
  60. });
  61. });