mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Rename `Chart.pluginService` to `Chart.plugins` (so move the old Chart.plugins array as a private member of the service), and rename `notifyPlugins` to `notify` for consistency with other service methods.
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
// Plugin tests
|
|
describe('Test the plugin system', function() {
|
|
var oldPlugins;
|
|
|
|
beforeAll(function() {
|
|
oldPlugins = Chart.plugins._plugins;
|
|
});
|
|
|
|
afterAll(function() {
|
|
Chart.plugins._plugins = oldPlugins;
|
|
});
|
|
|
|
beforeEach(function() {
|
|
Chart.plugins._plugins = [];
|
|
});
|
|
|
|
it ('Should register plugins', function() {
|
|
var myplugin = {};
|
|
Chart.plugins.register(myplugin);
|
|
expect(Chart.plugins._plugins.length).toBe(1);
|
|
|
|
// Should only add plugin once
|
|
Chart.plugins.register(myplugin);
|
|
expect(Chart.plugins._plugins.length).toBe(1);
|
|
});
|
|
|
|
it ('Should allow unregistering plugins', function() {
|
|
var myplugin = {};
|
|
Chart.plugins.register(myplugin);
|
|
expect(Chart.plugins._plugins.length).toBe(1);
|
|
|
|
// Should only add plugin once
|
|
Chart.plugins.remove(myplugin);
|
|
expect(Chart.plugins._plugins.length).toBe(0);
|
|
|
|
// Removing a plugin that doesn't exist should not error
|
|
Chart.plugins.remove(myplugin);
|
|
});
|
|
|
|
it ('Should allow notifying plugins', function() {
|
|
var myplugin = {
|
|
count: 0,
|
|
trigger: function(chart) {
|
|
myplugin.count = chart.count;
|
|
}
|
|
};
|
|
Chart.plugins.register(myplugin);
|
|
|
|
Chart.plugins.notify('trigger', [{ count: 10 }]);
|
|
|
|
expect(myplugin.count).toBe(10);
|
|
});
|
|
});
|