Get this repository: https://github.com/bhouser/jestReactMockTsx
In typescript subdirectory, do:
npm install --save-dev lodash @types/lodash
Replace ParentComponent.tsx with this content:
import * as React from 'react';
import ChildComponent from './ChildComponent';
import * as _ from 'lodash';
function x() {
return { ..._.isNil };
}
export default function ParentComponent() {
return (
<div
{ ...x() }
>
<div className="parentComponent">
<ChildComponent />;
</div>
</div>
);
}
You will see that usage of { ..._.isNil } makes the transformed source to omit the require for ChildComponent.
When you compile the project with tsc, it does it correctly.
I was using this in a real project and it was working. It was abandoned and when I get it again it was full of upgrade issues with react and react-router. After all updates, I'm having this problem.
I tried to downgrade typescript but I still see this with ts-jest.
please create a repo such that git clone, yarn install / npm install & yarn test / npm test reproduces the issue
Clone https://github.com/asfernandes/issue-ts-jest-198
npm install && npm test
@asfernandes thanks!
I was able to reproduce this. I'm not sure what's causing this but I'm marking this as a bug because it compiles fine with tsc
I spent few hours to debug a problem and I've found that the problem is already fixed in https://github.com/Microsoft/TypeScript/pull/15566
I've checked with [email protected] and yes, it works.
But if I didn't did a mistake, I tested with Typescript 2.1 and 2.2 and still saw the bug.
@asfernandes please try [email protected]
@asfernandes I just tried this with [email protected] and it passed the test.