Skip to content

Commit

Permalink
add testcases for event and changes on various files:
Browse files Browse the repository at this point in the history
  • Loading branch information
hashemirafsan committed Aug 24, 2022
1 parent 28b2d9e commit f68b69b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class DispatchableEvent implements IDispatcherEvent {

/**
* "This function adds a listener to the list of listeners."
*
*
* The first line of the function is the function declaration. It's a function named setListener that
* takes a parameter named listener. The parameter is of type IDispatcherListener. The function
* returns a DispatchableEvent
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { DispatcherEngine } from './engine';
import { DispatchableEvent } from './event';
import { DispatchableListener } from './listener';

export { DispatchableEvent, DispatchableListener, DispatcherEngine };
export { DispatchableEvent, DispatchableListener, DispatcherEngine };
4 changes: 2 additions & 2 deletions src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ function so that it can be used as a listener */
export class DispatchableListener implements IDispatcherListener {
private _isOnce: boolean = false;
private _expect: boolean = false;
private _listenerCallback: (args: object) => {};
private _listenerCallback: (args: object) => void;

constructor(listenerCallback: (args: object) => {}) {
constructor(listenerCallback: (args: object) => void) {
this._listenerCallback = listenerCallback;
}

Expand Down
17 changes: 0 additions & 17 deletions tests/trigger.test.ts

This file was deleted.

28 changes: 28 additions & 0 deletions tests/unit/event.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { DispatchableListener } from "../../src/listener";
import { DispatchableEvent } from "../../src/event";

describe('Dispatchable Event Suit', () => {
test('setName() set event name', () => {
const dispatchableEvent = new DispatchableEvent('new-event');
dispatchableEvent.setName('new-event-name');
expect(typeof dispatchableEvent.setName).toBe('function');
expect(dispatchableEvent.getName()).toBe('new-event-name');
});

test('getName() return event name', () => {
const dispatchableEvent = new DispatchableEvent('new-event');
expect(typeof dispatchableEvent.getName).toBe('function');
expect(dispatchableEvent.getName()).toBe('new-event');
});

test('setListener() set listener in event', () => {
const dispatchableEvent = new DispatchableEvent('new-event');
const listener = new DispatchableListener((args) => {
return {}
});
dispatchableEvent.setListener(listener);

expect(typeof dispatchableEvent.setListener).toBe('function');
expect(dispatchableEvent.getListeners().length).toBe(1);
});
})

0 comments on commit f68b69b

Please sign in to comment.