Open DanweDE opened 4 years ago
toEmitInTime
is used for observables that emit values over time, but we use it with lolex
to mock time. So the above example would be as follows:
const seq = Kefir.sequentially(100, [1, 2]).toProperty(() => 0)
expect(seq).toEmitInTime([
[0, value(0, { current: true })],
[100, value(1)],
[200, value(2)],
[200, end()],
], tick => {
tick(200);
});
Yes, I am aware of that. In theory that is sufficient, in practice it might not work when testing code that also relies on promises so I still think this suggestion would make a lot of sense for real-world testing cases. The second use-case where this would be helpful would be when in your tests you don't care about the exact time but just the order something emitted.
Ok, will reopen to investigate, but not sure when I'll get to it. Open to a PR though if you're interested!
Two things:
watch
returns the log
array and an unwatch
function, which in toEmit
is called synchronously, but it doesn't need to do that. I'm going to transfer this issue to the jest-kefir
repo.expect(obs).toEmit([...])
would now need to be await
'd. Instead of modifying toEmit
to allow async
functions, what do you think about a new matcher called toEmitAsync
that expects an async
function?
It would be great if
toEmit
(i.e.createTestHelpers(Kefir).watch
) would allow asserting that an observable emits, also asynchronously. For example: