Closed apellerano-pw closed 6 years ago
This sounds like the same issue in: https://github.com/Turbo87/ember-mocha-codemods/pull/26. would you mind confirming? I'm picking the codemod up again today to see if I can get it rewriting properly.
Yes it seems like the same issue to me. Thanks for making a fix!
cool thanks! no problem. I think I may have fixed the issue here: https://github.com/efx/ember-mocha-codemods/tree/fix-14 If you have time, you could try that branch against your codebase and let me know if you have any issues.
I ran it on a file, here is the before and after.
While it did convert the render to the one imported from @ember/test-helpers
, it didn't add async
or await
to the code so I don't think it would be a sufficient fix for my case
beforeEach(function () {
this.render(hbs`{{my-component
isActiveCollection=true
collection=collection
}}`);
});
beforeEach(function () {
render(hbs`{{my-component
isActiveCollection=true
collection=collection
}}`);
});
Here's an input file
import { expect } from 'chai';
import {
beforeEach,
context,
describe,
it,
} from 'mocha';
import { setupComponentTest } from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';
describe('Integration | Component | my-component', function () {
setupComponentTest('my-component', {
integration: true,
});
context('when in some situation or another', function () {
beforeEach(function () {
this.render(hbs`{{my-component}}`);
});
it('should do the thing', function () {
expect(true).to.be.true;
});
});
});
I ran it thru your fork with
jscodeshift -t https://raw.githubusercontent.com/efx/ember-mocha-codemods/fix-14/fourteen-testing-api.js fake-test.js
sweet, thanks for checking. I have found a few other bugs too. I will add this snippet above as a test too.
@apellerano-pw I just updated the branch with a passing test accounting for the context
hook. If it runs ok on your codebase, I'll open the PR.
ayyyy it worked! :tada:
Oh, if the problem was that the context()
alias wasn't working, what about the specify()
alias for it()
? I didn't see that in a quick search of the codemod either. This might be worthy of its own ticket
context() is just an alias for describe(), and behaves the same way; it just provides a way to keep tests easier to read and organized. Similarly, specify() is an alias for it().
good point. I think a new ticket is best so we can keep the PR's smaller.
I made #37 for it
Sometimes when tests have similar setups we use a
beforeEach
to callrender
. The codemod does a good job convertingit
usages to async functions but misses functions passed to other mocha hooks