Closed oskarer closed 6 years ago
Just to confirm, is it import/named
rule that is failing?
@asapach Correct, sorry for not clarifying that!
Does it still complain if you do it like this?
import * as utils from './utils.js';
utils.rewire$formatNumber();
...
utils.restore();
Nope, that works! It's not covered by the import/named
rule.
So will you be fine with using it like that? I think it's a preferred approach for large projects anyway, because you're likely to have multiple modules rewired, and it's easier to distinguish between them:
utils.restore();
services.restore();
You could also try using injector
from #8.
My solution now was doing;
/* eslint-disable import/named */
import {
rewire$someFunction,
rewire$anotherFunction,
restore as restoreSelectors,
} from './utils/selectors';
import {
rewire$helperFunction,
restore as restoreHelpers,
} from './utils/helpers';
/* eslint-enable import/named */
The downside of doing import * as
is that you don't get tree shaking. However this is not a super big issue in tests so doing your proposed solution will work just fine 👍
Thanks. I'll close the issue then.
When doing an import like;
eslint-plugin-import
is complaining aboutrewire$formatNumber
andrestore
does not exist in./utils.js
. Is there a way to make this lib make eslint aware of that those functions are available?