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

[Feature] Allow setting test description #71

Open
IanVS opened this issue Mar 2, 2022 · 2 comments
Open

[Feature] Allow setting test description #71

IanVS opened this issue Mar 2, 2022 · 2 comments
Labels
feature request New feature or request

Comments

@IanVS
Copy link
Member

IanVS commented Mar 2, 2022

Describe the Feature

Sometimes it is nice to give some extra context around what the test is doing, and I find that the story name is not always an ideal place for this. I've taken to just adding comments at the top of my play function, but these don't show up in the test result output of course. It might be nice to have a way to customize what is shown there instead of always just smoke-test or play-test.

Additional context

I'm not really sure how'd you'd accomplish this, short of adding another property onto CSF objects, which does not feel ideal. My only other idea would be to allow a return value from play functions, which you could use to pass before/after hooks, and maybe also a description.

@IanVS IanVS added the feature request New feature or request label Mar 2, 2022
@shilman
Copy link
Member

shilman commented Mar 2, 2022

What do you think about just making the test name the story name per #70

So rather than:

describe('MyComponent', () => {
  describe('Story1', () => {
    it('play-test', () => { ... });
  });
  describe('Story2', () => {
    ...
  });
});

You'd have:

describe('MyComponent', () => {
  it("Story1's story name", () => { ... });
  it("Story2's story name", () => { ... });
});

This would be consistent with the idea that the story is the combination of its render and play functions, so the story's name should be descriptive of both.

I could also see the need for a long-form description for the story and we could probably get it with story descriptions extracted from jsdoc comments, maybe with some kind of jsDoc tag to isolate the test-specific documentation. However AFAIK Jest doesn't have a place to specify that kind of information. WDYT:

@IanVS
Copy link
Member Author

IanVS commented Mar 7, 2022

However AFAIK Jest doesn't have a place to specify that kind of information

Hmmmm, I think that's where I'd want to use the it description. I actually kind of like the current structure of showing Component -> StoryName -> it description. But that said, I've started naming my stories that are just for tests in the ShouldDoAThing convention, which accomplishes two goals:

  • Identifies the story's purpose as being a test.
  • Gives some context around what the test is trying to accomplish.

Maybe that's enough for now. But, it can result in story names that are a little bit long for my taste. 😂 Also, sometimes I just want to throw some assertions on a story that's serving a different purpose, and don't need to create a special story just for the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants