just-jeb / jest-marbles

Helpers library for marbles testing with Jest
MIT License
112 stars 13 forks source link

Incorrect Subject test #542

Open DKozachenko opened 1 month ago

DKozachenko commented 1 month ago

Hello! I tried to test some subjects in my project and encountered on problem (or feature?). I created a separated spec file for showing you my misunderstanding.

subject

Test B works, because it's copied from docs. Test A (without scheduling using "schedule" function) doesn't work and tells me, that there is no emitted value. For me it's strange, because I call "next" method.

Mb I don't understand smth and it's a feature?

I will be glad any comments or description why it works like this

just-jeb commented 1 month ago

It's very simple - for tests we use a special scheduler that "fakes" the time and the frames. When you use one of the initialization methods provided by this library (like cold or hot) or when you use schedule method, the Subject is evaluated by this scheduler, hence integrated in the testing environment. When you just use .next then the internal test scheduler is not aware of this information, so the test fails.