kefirjs / kefir-test-utils

Framework-agnostic testing tools for Kefir
MIT License
0 stars 1 forks source link

Issue checking whether "end" was emitted on Kefir.never() #48

Closed DanweDE closed 4 years ago

DanweDE commented 4 years ago

I am using kefir-test-utils through https://github.com/kefirjs/jest-kefir and noticed the following failure:

      it('never emits', () => {
        const stream = K.never();
        expect(stream).toBeStream();                 // PASS
        expect(stream).not.toBeActiveObservable();   // PASS
        expect(stream).toEmit([kefirHelpers.end()]); // FAILURE
      });

with the FAILURE being:

    Difference:

    - Expected
    + Received

      Array [
        Object {
    -     "current": false,
    +     "current": true,
          "type": "end",
        },
      ]

Not sure why current: false is expected here, can anyone explain or confirm that this is a bug? Using Kefir 3.8.6 and latest version of testing packages as well.

mAAdhaTTah commented 4 years ago

No, that's correct. A never stream has a current value of end. That's a Kefir behavior, and it makes sense because a never stream is currently ended.

DanweDE commented 4 years ago

So the expect(stream).toEmit([kefirHelpers.end()]); line of the test is very unintuitive.

Why does kefirHelpers.end() include current: false then? Aren't all observables that ended currently ended? Thus type: "end" should always come with current: true, or am I missing something?

mAAdhaTTah commented 4 years ago

No. You could write a test like this:

const a = stream();
expect(a).toEmit([value(1), end()], () => {
  send(a, [value(1), end()]);
});

At the point the stream is subscribed, it is not ended. It emits an end later.

mAAdhaTTah commented 4 years ago

Also, to be clear, current is only relevant to Properties. Kefir has 2 Observable subtypes: Property & Stream, with Property being the one with a concept of current value. More info is in the docs: https://kefirjs.github.io/kefir/#about-observables

DanweDE commented 4 years ago

If current is only relevant to properties, then couldn't we just ignore current if the given observable is a stream and thus make

const stream = K.never();
expect(stream).toEmit([kefirHelpers.end()]);

pass? :thinking:

mAAdhaTTah commented 4 years ago

K.never returns a Property with a current value of end. That's all it is. This passes:


const stream = K.never();
expect(stream).toEmit([kefirHelpers.end({ current: true })]);

if you're trying to get the test to pass. Otherwise, everything is functioning as expected.