Skip to content

V2#3

Merged
RoySegall merged 14 commits intomasterfrom
v2
Jan 28, 2025
Merged

V2#3
RoySegall merged 14 commits intomasterfrom
v2

Conversation

@RoySegall
Copy link
Copy Markdown
Contributor

@RoySegall RoySegall commented Jan 21, 2025

A couple of notes about this one:

  1. I removed the part of the router we never got there
  2. I added a simple file because it seems mid level developers got messed with this
  3. I switched to vitest instead of mocha, or any test runner we had there

Signed-off-by: Roy Segall <roy@segall.io>
Signed-off-by: Roy Segall <roy@segall.io>
Signed-off-by: Roy Segall <roy@segall.io>
Signed-off-by: Roy Segall <roy@segall.io>
Signed-off-by: Roy Segall <roy@segall.io>
Signed-off-by: Roy Segall <roy@segall.io>
@RoySegall RoySegall marked this pull request as draft January 21, 2025 14:36
@RoySegall RoySegall requested review from liorama and removed request for liorama January 21, 2025 14:39
Signed-off-by: Roy Segall <roy@segall.io>
Signed-off-by: Roy Segall <roy@segall.io>
@RoySegall RoySegall requested a review from liorama January 22, 2025 07:46
@RoySegall RoySegall marked this pull request as ready for review January 22, 2025 07:46
Signed-off-by: Roy Segall <roy@segall.io>
README.md Outdated
* Do time yourself (the benchmark is approximately 30 minutes)
* You may use every resource you would naturally use as a developer, except for AI-based tools such as Co-Pilot, ChatGPT, Bard etc.
* Please send the completed exercise zipped (.zip, or if the mail blocks just change the extension to something else) to Dror Elovits (d.elovits@tricentis.com) within up to 48h
* Please send the completed exercise zipped (.zip, or if the mail blocks just change the extension to something else) to Dror Elovits (y.raz@tricentis.com) within up to 48h
Copy link
Copy Markdown
Contributor

@omril1 omril1 Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Please send the completed exercise zipped (.zip, or if the mail blocks just change the extension to something else) to Dror Elovits (y.raz@tricentis.com) within up to 48h
* Please send the completed exercise zipped (.zip, or if the mail blocks just change the extension to something else) to Yuval Raz (y.raz@tricentis.com) within up to 48h

emitter/part1.md Outdated
var f = new EventEmitter();
f.on("Hello", function(data){
```js
var eventEitter = new EventEmitter();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haters with typos?

@Shahar-Chen
Copy link
Copy Markdown

Why did we remove the router exercise? you think its not needed?

@RoySegall
Copy link
Copy Markdown
Contributor Author

Why did we remove the router exercise? you think its not needed?

We never asked it 🤷‍♂️🫤

Signed-off-by: Roy Segall <roy@segall.io>
Signed-off-by: Roy Segall <roy@segall.io>
@liorama
Copy link
Copy Markdown
Contributor

liorama commented Jan 22, 2025

@RoySegall The router is not a bad question for some scenarios. The solution to the problem of not giving it as a question might be, giving it as a question. We might just need to develop it a little. Please don't delete it.

Signed-off-by: Roy Segall <roy@segall.io>
@RoySegall
Copy link
Copy Markdown
Contributor Author

We might just need to develop it a little. Please don't delete it.

@stefandokic-tricentis refactored it but since he does not have a write permission i copied it. Need to verify it.

emitter/part2.md Outdated
Name your file `emitter.js` and export your class/constructor as `EventEmitter`. After you `npm i` you can execute `npm run test2`.

**We __encourage__ you to run the tests**. No newline at end of file
Name your file `Emitter.ts` and export your class/constructor as `EventEmitter`. After you `npm i` you can execute `npm run test:emitter:part1`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Name your file `Emitter.ts` and export your class/constructor as `EventEmitter`. After you `npm i` you can execute `npm run test:emitter:part1`.
Name your file `Emitter.ts` and export your class/constructor as `EventEmitter`. After you `npm i` you can execute `npm run test:emitter:part2`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what if someone wants to run with bun?

This is so runtime assuming

emitter.on("Hello", done);
emitter.trigger("Hello");

expect(done).toHaveBeenCalled();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really also test it has only been called once.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And check it did not happen before .trigger

Comment on lines +22 to +29
const handler = vi.fn((data) => {
expect(data).toBe("World");
});

emitter.on("Hello", handler);
emitter.trigger("Hello", "World");

expect(handler).toHaveBeenCalled();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const handler = vi.fn((data) => {
expect(data).toBe("World");
});
emitter.on("Hello", handler);
emitter.trigger("Hello", "World");
expect(handler).toHaveBeenCalled();
const handler = vi.fn();
emitter.on("Hello", handler);
emitter.trigger("Hello", "World");
expect(handler).toHaveBeenCalledWith("world");

});

it("can trigger an event with no handlers", () => {
expect(() => emitter.trigger("Hello")).not.toThrow();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best to also check there were no unhandled rejections, you never know what code people write


it("supports multiple event triggers same function", () => {
const trackedFunction = vi.fn();
const trackedFunctionNotToBeInvoked = vi.fn();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You never pass this function anywhere, how would it possibly be invoked?


beforeEach(() => {
emitter = new EventEmitter();
tracker = vi.fn();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You never actually use this?

expect(trackedFunction).toHaveBeenCalledTimes(1);
});

it("can remove and call off twice", () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already tested you can remove, this just checks calling twice won't cause any issues

Suggested change
it("can remove and call off twice", () => {
it("can call off twice", () => {

expect(trackedFunction).toHaveBeenCalledTimes(1);
});

it("removes the relevant event", () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("removes the relevant event", () => {
it("removes only the relevant event", () => {

Signed-off-by: Roy Segall <roy@segall.io>
@Shahar-Chen
Copy link
Copy Markdown

Although Chemi has some good comments, I think it looks good enough for the purpose of the code.
Light it up

@RoySegall RoySegall merged commit 1af327e into master Jan 28, 2025
@atlowChemi
Copy link
Copy Markdown

Although Chemi has some good comments, I think it looks good enough for the purpose of the code. Light it up ![]

מתפשרים על שאלות ראיון === מתפשרים על מועמדים, רק אומר

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants