core.plugin.tests.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Plugin tests
  2. describe('Test the plugin system', function() {
  3. beforeEach(function() {
  4. Chart.plugins = [];
  5. });
  6. it ('Should register plugins', function() {
  7. var myplugin = {};
  8. Chart.pluginService.register(myplugin);
  9. expect(Chart.plugins.length).toBe(1);
  10. // Should only add plugin once
  11. Chart.pluginService.register(myplugin);
  12. expect(Chart.plugins.length).toBe(1);
  13. });
  14. it ('Should allow unregistering plugins', function() {
  15. var myplugin = {};
  16. Chart.pluginService.register(myplugin);
  17. expect(Chart.plugins.length).toBe(1);
  18. // Should only add plugin once
  19. Chart.pluginService.remove(myplugin);
  20. expect(Chart.plugins.length).toBe(0);
  21. // Removing a plugin that doesn't exist should not error
  22. Chart.pluginService.remove(myplugin);
  23. });
  24. it ('Should allow notifying plugins', function() {
  25. var myplugin = {
  26. count: 0,
  27. trigger: function(chart) {
  28. myplugin.count = chart.count;
  29. }
  30. };
  31. Chart.pluginService.register(myplugin);
  32. Chart.pluginService.notifyPlugins('trigger', [{ count: 10 }]);
  33. expect(myplugin.count).toBe(10);
  34. });
  35. });