Thanks Dan for writing this article. It sounds like a direction I would like to go to. I have one question though. How would you solve for Typescript the fact that cypress ui tests need to run on different environments? Meaning you would have to create/load test data objects with different values for different environments. I would appreciate if you could share your thoughts about it. Thanks 😊
My apologies for not seeing this question sooner. So I would first ask thy you would need different data for mocked tests. Generally mocked tests are designed to test the "shape" of your data, not necessarily real data. As where end-to-end (e2e) tests would rely on both the shape and the content of the data and would therefore not utilize mock data (or factories) at all.
But if you still choose to mock different data per environment, I would consider simply clarifying that in your tests.
letuser:IUser|null=null;if(process.env.NODE_ENV==='production'){user=makeFakeUser({userName:'John'});}elseif(process.env.NODE_ENV==='staging'){user=makeFakeUser({userName:'Susan'});}// Assert so that the user variable can no longer be seen as nullif(!user){thrownewError(`unable to initialize mock user since NODE_ENV was invalid`);}// the rest of your test
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks Dan for writing this article. It sounds like a direction I would like to go to. I have one question though. How would you solve for Typescript the fact that cypress ui tests need to run on different environments? Meaning you would have to create/load test data objects with different values for different environments. I would appreciate if you could share your thoughts about it. Thanks 😊
My apologies for not seeing this question sooner. So I would first ask thy you would need different data for mocked tests. Generally mocked tests are designed to test the "shape" of your data, not necessarily real data. As where end-to-end (e2e) tests would rely on both the shape and the content of the data and would therefore not utilize mock data (or factories) at all.
But if you still choose to mock different data per environment, I would consider simply clarifying that in your tests.