rescript-jest icon indicating copy to clipboard operation
rescript-jest copied to clipboard

How would addSnapshotSerializer fit in bs-jest?

Open davesnx opened this issue 5 years ago • 1 comments

Hey @glennsl

I was trying to add the "binding" to expect.addSnapshotSerializer() in bs-jest and I found creating too much crap for this particular case.

How it works it's simple, while expect.extend adds prototype methods to the matches, expect.addSnapshotSerializer adds transformations to the snapshots and both methods are called once on top of the file (or in any setup.js file)

That's a valid serializer:

const serializer = {
	test: () => true
	print: (value) => JSON.stringify(value)
}

expect.addSnapshotSerializer(serializer);

So, a serializer it's a

type serializer = <
  test :value -> bool;
  print :value -> serialize -> indent -> string
> Js.t

But I end up adding addSnapshotSerializer to the prototype with the affirm. Would you mind some advice on how to add it without too much hassle?

Thanks!

davesnx avatar Apr 19 '20 15:04 davesnx

Hey. Sorry for the late response. It's a bit of a chore just to get into this as I don't even use bs-jest regularly these days.

I think you could just implement this as a standalone binding though. Noe need to involve any of the existing stuff. Just put an ordinary external in the Expect module, and that's that. Or am I missing something?

glennsl avatar Apr 23 '20 16:04 glennsl