However I'm finding this a bit too rigid, as in some cases I don't have the userId since a fake user instance is used to authenticate. It requires me to do some weird manipulations in order to make the tests work. It would be neat if we could do something like this:
In this way, any calls to db.getById that matches my regex would receive the authToken mocked value, without having to be too granular/specific.
This also applies really well when you have to provide a URL as a parameter, or some other long string literal that contains dynamic values.
Context:
I am trying to stub out calls to my database in my tests to return a specific object, this is what the code looks like:
However I'm finding this a bit too rigid, as in some cases I don't have the
userId
since a fake user instance is used to authenticate. It requires me to do some weird manipulations in order to make the tests work. It would be neat if we could do something like this:In this way, any calls to
db.getById
that matches my regex would receive theauthToken
mocked value, without having to be too granular/specific. This also applies really well when you have to provide a URL as a parameter, or some other long string literal that contains dynamic values.