Skip to content
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

Add support for adding a displayName property for the returned Loadable component #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add support for adding a displayName property for the returned Loadable component #226

wants to merge 1 commit into from

Conversation

backyardcoder
Copy link

@backyardcoder backyardcoder commented Mar 9, 2020

The primary reason to introduce this change is to provide a way to aid the testing of components that consumes a Loadable component.
For example:

// In source code file:
const MyComponent = Loadable({
  displayName: 'MyComponent', // same as the import name and guaranteed to be unique in the "sut"
  loader: () => ...,
  loading: () => ...
});

// In test file
import MyComponent from '../my-path';

fakeLoader.withArgs({
   displayName: 'MyComponent',
   loader: sinon.match.func,
   loading: sinon.match.func
}).returns(MyComponent);

With the help of displayName, one can use a package like proxyquire to set up the correct fake loader stub to return expected components.

@backyardcoder
Copy link
Author

What do you think about adding this support, @jamiebuilds @tajo?

@StefanMcCready
Copy link

StefanMcCready commented Jul 1, 2020

It would be super cool to have this as part of the project. For a certain project, I am relying on the component displayName to help pick out certain components from children. Since we have moved to use react-loadable we have not been able to do this.

Repository owner deleted a comment from ygs-code Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants