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

Migrating from expect.js breaks assertions on exceptions

Open selbekk opened this issue 6 years ago • 2 comments

I was migrating a code base from Automattic's expect.js, and I noticed that my .withArgs-calls simply disappeared.

Here's a repo with a reproducible demo: https://github.com/selbekk/reproduce-jest-codemods-error

Now, I realize that you COULD write an inline function that would pass these arguments to the function, and that's what I've been doing manually now - but it shouldn't just remove this - at the very least it should warn that I need to fix some stuff manually. When searching through the code for this project, I didn't even find a mention of withArgs - even though it's in the documented API.

Sorry I can't fix this with a PR - I need to sit down and learn codemods and ASTs first, I guess =) But at least there's a reproducible demo you can hack away at!

Please let me know if there's anything I can do to help!

selbekk avatar Feb 08 '18 14:02 selbekk

Thanks you so much for the repoducable bug report!

Can you reveal what transformation you manually do right now to get it to work?

Thanks. : )

skovhus avatar Feb 08 '18 18:02 skovhus

Sorry for not replying right away - posting code examples from my phone turned out to be a nightmare 😁

I'd expect the following diff:

- expect(someFn).withArgs('arbitrary', 'args').to.throw()
+ expect(() => someFn('arbitrary', 'args')).toThrow()

This is what I went through and did for my entire codebase - a good hour of looking through a diff and correcting :P I totally understand that this might be hard to implement, but perhaps we can warn about them instead of just removing them?

selbekk avatar Feb 09 '18 07:02 selbekk