And we have a lot of questions for you from our Discord channel, but before questions for you, let's have a look what folks answered on your question. So I open Slido, and wow, that's really interesting. So we have equal number of votes for two answers and they leaving these two with a large margin. So one half of the people answered not yet, yes, I'm not using state machine, and other half of people answered yes, I use it with a library. That's really interesting.
So what do you think about these results, David? And welcome to our studio. Thank you, I think that they're surprising but not too surprising because if you were to ask this question maybe a year ago or three years ago, you would have people saying mostly no or not yet. And they would be saying that because state machines have traditionally been a very, I guess you could say an academic topic, not a topic that's really prevalent in software development, unless you've studied things like UML or embedded electronics, or just formal patterns and stuff like that. But now we're seeing that more and more people are understanding the value of using state machines and state charts to model their application state. So it's really encouraging that a lot of people are using state machines in their applications now.
Yeah, yeah, yeah, fair enough. And I think there was a trick in your question because I didn't pay maybe too much attention to the exact wording and I've seen something, oh, something about state. Yes, I use, of course I use state library, but it was not about just generic state library. It was about state machine. And yeah, personally, I didn't use it in my project myself. So maybe after your session, I will definitely give it a try. Well, let's see what our dear attendees want to ask you. Yes, let's keep the question about future for the future. We have enough time to do this. Very, very practical one. How does testing look like in X state world? Well, testing looks great. And so there's two angles to this question. First is testing the state machines in X state itself. The state machines, like I showed, they have a transition function. These are pure functions, which means that if you want to test that after a user does X number of events, it ends up in a certain state, you could just do that. You could send the events to this pure transition function of the machine and just assert that it is in the states that you expect it to be. And not only that, you could do like state.matches or with the new tag, you can do state.hasTag and just make sure that not only you get the correct states but also that the correct events are fired. And on the other side of this, there is a library, an accessory library, to Xstate called Xstate-test, and so that allows you to do much further than just testing your state machines. You can test entire applications even if they're not written with state machines at all, and it doesn't matter which framework they're in. What you do is you describe your model as a state machine, or like the model of the application, and you model it as a state machine, and you run that through Xstate-test, which is going to generate automatically all possible ways that the user could go through the application and ensure that all of the expected states are reached.
Comments