Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test MediaViewModel #2598

Merged
merged 1 commit into from
Sep 3, 2024
Merged

Conversation

robintown
Copy link
Member

@robintown robintown commented Aug 30, 2024

This was the result of me playing around with RxJS marble testing to understand how to get things done with its TestScheduler. I discovered that it lacks a clear way to fire arbitrary actions during the test, so I built a small helper function called schedule which does this for us.

This was the result of me playing around with RxJS marble testing to understand how to get things done with its TestScheduler. I discovered that it lacks a clear way to fire arbitrary actions during the test, so I built a small helper function called schedule which does this for us.
Copy link
Contributor

@toger5 toger5 left a comment

Choose a reason for hiding this comment

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

Cool this looks nice.
I am not sure where exactly it makes the most sense to do the abstraction cut.
creating the new testScheduler and using the deep.equals from vitest definitely should be abstracted.
I think we might also want a withTestScheduler that does not enforce the marbles -> action pattern. So I am wondering if we should already call it withActionTestScheduler? (easy to refactor afterwards however so I will approve for now.

@robintown robintown merged commit 1784cb2 into element-hq:livekit Sep 3, 2024
5 checks passed
@robintown
Copy link
Member Author

I think we might also want a withTestScheduler that does not enforce the marbles -> action pattern.

What do you mean by this? Are you saying it would be nice to have a variant that lets you run observables and actions in real time? That's what you already get when writing a test without TestScheduler.

@toger5
Copy link
Contributor

toger5 commented Sep 9, 2024

I am wondering if this:

export function withTestScheduler(
  continuation: (helpers: OurRunHelpers) => void,
): void {
  new TestScheduler((actual, expected) => {
    expect(actual).deep.equals(expected);
  }).run((helpers) =>
    continuation(helpers),
  );
}

On its own is already helpful?
But thinking it through:

withTestScheduler((helpers)=>{
  // some custom rxjs testing
  helpers.cold("some_marbels").pipe(...);
  // some custom checks
  helpers.expectObservable()...;
})

VS

new TestScheduler((actual, expected) => {
  expect(actual).deep.equals(expected);
}).run((helpers) =>
  // some custom rxjs testing
  helpers.cold("some_marbels").pipe(...);
  // some custom checks
  helpers.expectObservable()...;
);

might not be enough of a simplification to justify the reduced explicity.

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.

2 participants