You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library is analogous to let in rspec, but there isn't an equivalent for let!. We are using it for cypress tests and we almost always want to eagerly evaluate our given variables (because they correspond to API calls we want to resolve before the test starts), so it would be really nice if there was a shorthand for this eager evaluation. Currently our tests looks something like
But if this library supported that behavior we could remove the beforeEach. There are a few APIs I have thought might work but I'm open to other suggestions:
// lots of different naming options here - now / eager / bang / other ideas?given.now('a',()=>createSomething());// this one is a bit more complex to implement but I think it can be made to work with template literal types// https://www.typescriptlang.org/docs/handbook/2/template-literal-types.htmlgiven('!a',()=>=>createSomething());// or to make it look less like a boolean operatorgiven('a!',()=>=>createSomething());
I think this is relatively easy to implement by adding a __lazy__ property to the given object (pretty much identical to the __props__ property), and pushing in true or false based on how this function is called. Then you can add a beforeEach that checks the top of the list to decide if it should access given[key]. I'm happy to submit a PR if we can agree on an API.
The text was updated successfully, but these errors were encountered:
This library is analogous to
let
in rspec, but there isn't an equivalent forlet!
. We are using it for cypress tests and we almost always want to eagerly evaluate ourgiven
variables (because they correspond to API calls we want to resolve before the test starts), so it would be really nice if there was a shorthand for this eager evaluation. Currently our tests looks something likeBut if this library supported that behavior we could remove the
beforeEach
. There are a few APIs I have thought might work but I'm open to other suggestions:I think this is relatively easy to implement by adding a
__lazy__
property to thegiven
object (pretty much identical to the__props__
property), and pushing intrue
orfalse
based on how this function is called. Then you can add abeforeEach
that checks the top of the list to decide if it should accessgiven[key]
. I'm happy to submit a PR if we can agree on an API.The text was updated successfully, but these errors were encountered: