wisemapping-frontend/packages/mindplot/test/unit/EventsTestSuite.js

42 lines
1.4 KiB
JavaScript
Raw Normal View History

const TestClass = new Class({
Extends: mindplot.Events,
2021-07-16 16:41:58 +02:00
getEvents() {
return this.$events;
},
2021-07-16 16:41:58 +02:00
removeEvents() {
this.$events = {};
},
2021-07-16 16:41:58 +02:00
});
// Test class and variables
const expectedChangeFn1 = function () { return 'change1'; };
const expectedChangeFn2 = function () { return 'change2'; };
const expectedLoadFn = function () { return 'loaded'; };
const myTestClass = new TestClass();
2021-07-16 16:41:58 +02:00
describe('Events class suite', () => {
afterEach(() => {
myTestClass.removeEvents();
});
2021-07-16 16:41:58 +02:00
it('addEventTest', () => {
expect(myTestClass.getEvents()).toEqual({});
myTestClass.addEvent('change', expectedChangeFn1);
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1] });
myTestClass.addEvent('change', expectedChangeFn2);
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1, expectedChangeFn2] });
myTestClass.addEvent('load', expectedLoadFn);
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1, expectedChangeFn2], load: [expectedLoadFn] });
});
it('removeEventTest', () => {
expect(myTestClass.getEvents()).toEqual({});
myTestClass.addEvent('change', expectedChangeFn1);
myTestClass.addEvent('change', expectedChangeFn2);
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1, expectedChangeFn2] });
myTestClass.removeEvent('change', expectedChangeFn1);
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn2] });
});
2021-07-16 16:41:58 +02:00
});