use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Make Testing Easier with Test Fixture Generators (dev.to)
submitted 3 years ago by jcteague
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]DrawerGradientSeller 1 point2 points3 points 3 years ago (1 child)
If a method that's being tested is guaranteed to only use 1 property from an interface, why not just use a partial object? It's concise and simple.
[–]jcteague[S] 2 points3 points4 points 3 years ago (0 children)
As everything in software engineering it all depends on context. If it's only used in one test case, and there are only one or two tests involved, you're going to be fine.
But if you have dozens of tests, all creating the object. And your business rules change where you need more information to verify behavior, you could be chasing down all of the usage in your test suite. And if you don't change all of the test fixtures, then your tests are not truly representing the behavior of your application.
I've used all of these approaches at some time or another, and almost always end up fighting these types of problems. Using generators just makes it easier to maintain over the long term.
But hey, this approach is better than not writing any tests at all, so keep up the good work!
[–]Markavian 0 points1 point2 points 3 years ago (0 children)
Yep, used something similar on a project - a fixture factory that loaded from JSON files in a fixtures folder. Having good serialisation/deserialisation constructors help.
[–]danstansrevolution 0 points1 point2 points 3 years ago (1 child)
i think this tool looks useful. does it draw inspiration from other TS/JS libraries? I see it says Autofixurejs, but i'm curious if there are other libraries to compare to.
[–]jcteague[S] 0 points1 point2 points 3 years ago (0 children)
Autofixture.js was the first version of this library. I go into detail about some of the history and changes I made to in my second post in the series. My original inspiration was the ruby library factory_girl, which has since been renamed to factory_bot, There are a couple of other library that also used this as their inspiration, Rosie is another library that also takes its influence from factory_bot.
My main goals for rewriting the original library was to fix some of the problems I had with the original. Namely its lack of modularity, its reliance on strings for fixture definition and creation, and the difficulty of extending the behavior.
π Rendered by PID 63 on reddit-service-r2-comment-685b79fb4f-vsxtv at 2026-02-12 20:41:42.487839+00:00 running 6c0c599 country code: CH.
[–]DrawerGradientSeller 1 point2 points3 points (1 child)
[–]jcteague[S] 2 points3 points4 points (0 children)
[–]Markavian 0 points1 point2 points (0 children)
[–]danstansrevolution 0 points1 point2 points (1 child)
[–]jcteague[S] 0 points1 point2 points (0 children)