Skip to content

Commit

Permalink
feat: implements proxyevent at apply handler
Browse files Browse the repository at this point in the history
  • Loading branch information
drusco committed Mar 10, 2024
1 parent 00dce73 commit 6653da0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/events/ProxyEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ProxyEvent {
name: Nexo.events.name;
proxy: Nexo.Proxy;
#defaultPrevented: boolean = false;
#returnValue: unknown;

constructor(
name: Nexo.events.name,
Expand All @@ -26,9 +27,17 @@ class ProxyEvent {
this.#defaultPrevented = true;
}

get defaultPrevented() {
next(value?: unknown): void {
this.#returnValue = value;
}

get defaultPrevented(): boolean {
return this.#defaultPrevented;
}

get returnValue(): unknown {
return this.#returnValue;
}
}

export default ProxyEvent;
2 changes: 1 addition & 1 deletion src/events/handlers/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const apply = (mock: Nexo.Mock, that?: unknown, args?: unknown[]): unknown => {
scope.emit(event.name, event);

if (event.defaultPrevented) {
return;
return event.returnValue;
}

if (typeof target === "function") {
Expand Down

0 comments on commit 6653da0

Please sign in to comment.