2021-12-02 01:41:56 +01:00
|
|
|
const TestClass = new Class({
|
|
|
|
Extends: mindplot.Events,
|
2021-07-16 16:41:58 +02:00
|
|
|
|
2021-12-02 01:41:56 +01:00
|
|
|
getEvents() {
|
|
|
|
return this.$events;
|
|
|
|
},
|
2021-07-16 16:41:58 +02:00
|
|
|
|
2021-12-02 01:41:56 +01:00
|
|
|
removeEvents() {
|
|
|
|
this.$events = {};
|
|
|
|
},
|
2021-07-16 16:41:58 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Test class and variables
|
2021-12-02 01:41:56 +01:00
|
|
|
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
|
|
|
|
2021-12-02 01:41:56 +01:00
|
|
|
describe('Events class suite', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
myTestClass.removeEvents();
|
|
|
|
});
|
2021-07-16 16:41:58 +02:00
|
|
|
|
2021-12-02 01:41:56 +01: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
|
|
|
});
|