Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.3k
"Invocations on test machines are not supported" when machines invoke actors#5353
-
I have this machine that uses
Couldn't find any answer anywhere. Will this be ever supported? |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 1 reply
-
Model-based testing is based on synchronous state transitions. The core principle is But when you invoke an actor, they are "alive" and asynchronous. Test path generation requires determinism, and when we're invoking live actors, it becomes non-deterministic. Can you give me a better idea of what you're trying to do? I can see a potential feature in which we can "simulate" invoked actors such that they are deterministic and synchronous, such as a promise that always resolves/rejects with the same value. |
BetaWas this translation helpful?Give feedback.
All reactions
-
My code looks something like this // Production upload actor implementationexportconstcreateUploadFileActor=()=>fromPromise(async({ input}:{input:{file:File;userId:string}}):Promise<ProfileData>=>{// get file from the dom and send it through an api call});// the actual machinereturnsetup({types:{context:{}asFileUploadContext,events:{}asFileUploadEvent,},actors:{uploadFile:createUploadFileActor(), ...actors},}).createMachine({id:'fileUpload',initial:'idle',context:{},states:{idle:{on:{UPLOAD_FILE:{target:'uploading',actions:assign({file:({ event})=>event.file,error:null,}),},},},uploading:{invoke:{id:'uploadFile',src:'uploadFile',input:({ context}:{context:FileUploadContext})=>({file:context.file!,userId:context.userId,}),onDone:{target:'success'...},onError:{target:'error'...},}, ...,}, As you can see, per the recommended way of handling "side effects" we've use the describe('Success Scenarios',()=>{constmockActor=fromPromise(async({input:_input}:{input:{file:File;userId:string}}):Promise<ProfileData>=>{awaitnewPromise(resolve=>setTimeout(resolve,100));returnmockSuccessProfileData;});constmachine=createFileUploadMachine(userId,mockOnProfileParsed).provide({actors:{uploadFile:mockActor,},});constmodel=createTestModel(machine);constpaths=model.getShortestPaths();paths.forEach((path)=>{it(path.description,async()=>{render(<MyComponent/>);awaitpath.test({states:{ ...},events:{ ...}});});});}); So the only thing impeding full MBT (model based testing) with xstate is the actor. I don't really care about the actual actor, in fact we are trying to mock it, so it seems like xstate could provide an easy way of mocking an actor with something that makes it "deterministic and synchronous" so that we can run full MBT on pretty much any machine. Alternatively we could, instead of the actor, we could model Also, is it not that actors are just instances of a machine? Is it not that Also, happy to contribute to this |
BetaWas this translation helpful?Give feedback.