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

40 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-12-05 00:39:20 +01:00
class TestClass extends Events{
getEvents() {
return this.$events;
2021-12-05 00:39:20 +01:00
}
2021-07-16 16:41:58 +02:00
removeEvents() {
this.$events = {};
2021-12-05 00:39:20 +01:00
}
}
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
});