Unit tests are great... when they work dependably! In fact, there's an old saying that "a bad test is worse than no test at all." I can attest that...
For further actions, you may consider blocking this person and/or reporting abuse
Loving every bit of this! Thanks Dan!
Thanks you so much for the positive energy. It certainly has been a pattern that has worked well for the teams at our company in the time since we adopted the pattern.
Just for curiosity.- To avoid this error
Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.
, without using your library, can I solve it by adding the!
at the end of the property I want to use (I mean, something like this:const field: string = faker().field!;
)?To avoid that error you have to check to see that the variable is not undefined.
So
Ok!
Great write up, thanks for taking the time to describe the issue. Just ran into similar issues, and this provides clear fixes + is a great reference for my team.
Thank you kindly Ben. And please ask them to share with others. I’d like to see this become a standard within the TS Cypress community.
Again, it’s so generous of you to say thank you. Isn’t dev.to such a wonderful community? :)
Very nice article, @dan
Is this supposed to read "So they add deleted: true..." or am I confused?
🔥🔥🔥
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.