-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IconNames is undefined in unit tests #4504
Comments
@Pajn Could supply a repro or code sample? |
This is easy to repro. create-react-app my-app --scripts-version=react-scripts-ts
yarn add office-ui-fabric-react @types/prop-types prop-types @uifabric/icons
yarn start In the App.tsx, use import { IconNames } from '@uifabric/icons/lib/IconNames';
import { Icon } from 'office-ui-fabric-react';
...
<Icon iconName={IconNames.Download} /> Will compile just fine, but at runtime You can see the declaration being correctly defined in @RyanCavanaugh might know what to do here. |
If we remove the Another possibility is to export each individual name as an individual const... they will treeshake out properly once we convert the |
This compiles correctly if you use The most likely problem here is that Assuming that's the case, then whoever configured this starter project should have put It's also possible that
Honestly |
This is in unit tests so it is unrelated to Webpack or I don't want to have |
@RyanCavanaugh Right now, users do type "download" for the icon name.
But they want intellisense:
So that's why the const enum; we just want the Hmmm there has to be something you can do here with ts-jest. |
ts-jest issue: Related note: I don't see any workaround here other than: Option 1: export the icons names as consts; export const Download = 'download'; Option 2: a full on object (nicer from the autocomplete perspective, worse because you get the whole thing and all the unused entries won't tree shake out): export const IconNames = {
Download: 'download'
}; Option 3: a non-const enum (which is even worse because of no tree shaking, plus enums are twice as heavy as plain objects): export enum IconNames {
Download = 'download'
} |
Another idea is to add a non-const, non exported enum to the package, so that at the |
TypeScript already provides Intellisense when you're typing a string in a place where the contextual type is a string literal type, so you don't really gain a whole lot with using a symbolic name instead. |
@cliffkoh is there a way we can adjust the typings of Icons? I am a bit confused on the right way to do this. |
Wanted to give this one a little nudge to see if there's any ideas on how we can resolve this. |
@dzearing, there's an internal email thread about this with the OneDrive & Gearbox folks. I ended my last part asking for an opinion from you: "Given the usage, I am proposing that we end up deprecating the IconNames enum for 7.x. For now, we should tag that object as @deprecated to discourage use. @dzearing – what’s your opinion?" In the meantime, internally within the Fabric codebase, we should remove the use of these IconNames enum altogether and just use strings like the library consumers should. So then the unit tests would be an issue. |
@dzearing - I took a look at our codebase and can't find usage of the IconNames enum anymore except inside a visual regression test story for Nav. (I searched for "IconNames."). I think this bug is actually addressed. @Pajn - it seems that |
This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your contributions to Fabric React! |
Bug Report
Priorities and help requested (not applicable if asking question):
Are you willing to submit a PR to fix? No
Requested priority: Blocking
Products/sites affected: Not yet public
Describe the issue:
IconNames from @uifabric/icons is undefined in our unit tests which makes it impossible to create any unit test in code which uses fabric icons. This occurs event if we set up the icons with initializeIcons in a Jest setupFile.
Actual behavior:
IconNames is undefined
Expected behavior:
IconNames is not undefined so that code can refer to icons in IconNames without crashing due to reading a property of undefined.
If applicable, please provide a codepen repro:
N/A
The text was updated successfully, but these errors were encountered: