Jest: Is it possible to show Function name instead of {[Function]} ?

Created on 10 Aug 2017  路  5Comments  路  Source: facebook/jest

On React, I have a <Button> with a prop that passs another component:

import Button from 'components/react-button';
import { IconBag } from 'components/react-icons';

<Button theme="primary" Icon={ IconBag }>Add to Bag</Button>

And on the snapshot it shows this:

<Button Icon={[Function]} theme="primary">Add to Bag</Button>

If I change the Icon prop value to another component, the snapshots doesn't change, staying {[Function]}.

Is it possible to know the function name on the snapshot? Something like:

<Button Icon={[Function IconBag]} theme="primary">Add to Bag</Button>

I have jest 18.1.0 installed.

Thanks

All 5 comments

We disabled this in Jest 16 for various reasons: https://facebook.github.io/jest/blog/2016/10/03/jest-16.html#snapshot-updates

Is it possible to somehow enable that in certain cases?

No, it's not configurable now. You can always fork jest-snapshot and remove printFunctionName: false part.

Thanks, i'll take a look!
Do u guys have plans to have option for it?

Not at this point, if you are using code coverage then the name won't be able to be inferred properly.

Was this page helpful?
0 / 5 - 0 ratings