jeudi 24 août 2017

How to unit-test rxjs5?

I've read through this "marble-string" docs, but I juts don't get it.

What I want to test is basically a "protocol". I have a "thing" which is connected to an Observable and which emits data. In my backend code with Rx.NET and C# I have written a helper to test protocols so that my tests look like this:

verifier.Send(new AddMaterialPickCommand(commandId, orderId, materialId: Guid.NewGuid(), quantity: 1))
            .FailWhen<CommandFailedEvent>(e => e.CommandId == commandId)
            .ThenExpect<MaterialPickAddedEvent>(e => e.EntityId == orderId)
            .ThenSend(new DeleteOrderCommand(commandId, orderId))
            .FailWhen<CommandFailedEvent>(e => e.CommandId == commandId)
            .ThenExpect<OrderDeletedEvent>(e => e.EntityId == orderId)
            .ExecuteAndWait(Timeout);

In C# its very easy to connect observables to all things and its also very easy to wait. IMO it is a very readable test code.

With Rxjs5, I didn't find any possibility to wait or do anything similar. So atm I'm failing at just checking that a single thing emitted by my observable is the one expected:

sut.setValue("key1", "key2");
sut.getObservable("key1", "key2")
    .subscribe(value => {
       expect(value).toBe("testValue")  // I want either execute this or fail after a timeout
    });

setValue actually calls next() on a BehaviourSubject.

I'm clueless, any ideas?

Aucun commentaire:

Enregistrer un commentaire