skovhus / jest-codemods

Codemods for migrating to Jest https://github.com/facebook/jest 👾
MIT License
881 stars 82 forks source link

Ava contexts not transformed #97

Open elijahdorman opened 6 years ago

elijahdorman commented 6 years ago
test.beforeEach(t => {
  t.context.fn = () => 'foo';
});

test('will execute foo', t => {
  t.is(t.context.fn(), 'foo');
});

The t.is will be modified, but the t.context will be left in place and cause errors. Perhaps renaming and moving to the file closure would work.

https://github.com/avajs/ava#test-context

skovhus commented 6 years ago

Thanks for reporting this. Let me know if you would like to try to fix it. : )

jamonholmgren commented 6 years ago

I ran into this issue as well. The easiest fix was to add this at the beginning:

const t = { context: { fn: null } }

test.beforeEach(t => {
  t.context.fn = () => 'foo';
});

test('will execute foo', t => {
  t.is(t.context.fn(), 'foo');
});