Let's take a look at the low-level spying and mocking capabilities, comparing SignOn and Jest. On the left side, we have SignOn. On the right side, we have Jest. SciSpy versus JeftSpyOn have similar APIs, taking an object and a method. To have been called dot notation versus camel case syntax, similar APIs, we have some alternatives on the SignOn side, but they do the same thing.
Matching strings or expecting any, that's a one-on-one comparison also. Custom matchers, you have these conveniences on the SignOn side and they're pretty easy to use and straightforward. It's possible to do the same thing on the Jest side, but it takes a little bit of work, so you have to create those yourself if you want to have custom matchers. That's why you don't see them too often.
Asyngonist testing, being able to create the spy is pretty much the same on either side. On the Cypher side, you can wrap the promise, the side wrap, and then make an assertion on it directly. On the RTL side, you have to gather all the promises first and then do a promise all. That way, you can verify the order of them, so the first call is 4 and 5, second call is 1 and 90, by adding these things together. On the Cypher side, it's kind of inferred because we called this one first, so that should be called first, and then called this one second, that should be called second. They're slightly different in asynchronous testing but at the end, again, we accomplish the same thing.
Let's make a contrast and take a look at the stubs and mocks. CyStub is directly comparable to JestFn to be able to stub something, object methods similar to CySpy API, with Jest, though, slightly different. We're all used to mock implementations and how we do it, but it does come from, hey, is this a spy or is this really a mock? In Jest, this is how we do it. We've been used to it, we've been doing this all the time, so it's easy to understand. I sometimes get confused what's the difference between mock implementation versus mock return value, but when you flip it to the Cynos side, it's clear. The mock return value is an extra, making sure that you're returning a certain method from the stubbing of the method. When we deal with promises and further make things a little more sophisticated, with Cynon we have some nice abstractions. Object method being called with var return foo, it's nice and declarative. Doing the same on the Jest side, yielding the argument, conditional. Yes, it's a bit of work, but it's possible. Following a promise, again, nicely abstracted. It's possible on the RTL side, but it takes a bit of work. Rejecting a promise, again, the same approach. But in the React committee, we've been used to these difficult ways of working with Jest. We have built some expertise on this, so definitely there's going to be some vested interest over there.
Comments