react-ab icon indicating copy to clipboard operation
react-ab copied to clipboard

Choose specific variant when required

Open laytong opened this issue 9 years ago • 3 comments

In our workplace we use visual diffing tools on snapshots as part of our regression testing.

When taking snapshots for our diffs it would be useful if we could specify a variant by name to keep our visual diffs consistent while a/b testing.

It looks like this is almost possible looking at the API docs, please let me know if this is possible.

laytong avatar Jul 07 '16 06:07 laytong

It's possible to keep it consistent by setting the random or the get prop. For example:

function random() {
  if (TESTING) {
    return 0
  }

  return Math.random()
}

olahol avatar Jul 07 '16 13:07 olahol

Hey, thanks for getting back to me.

This almost works as I want. Once a user's variant has been set (i.e. they already have a cookie set) I want that to be used. I just want to override in that specific instance.

laytong avatar Jul 07 '16 21:07 laytong

You can also modify the get prop.

<Experiment get={(key) => {
   if (cookie.get(key)) {
      return cookie.get(key)
   }

   return "variant"
}} />

olahol avatar Jul 13 '16 23:07 olahol