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

dynamic test name #1

Open
maciejw opened this issue Feb 9, 2018 · 4 comments
Open

dynamic test name #1

maciejw opened this issue Feb 9, 2018 · 4 comments

Comments

@maciejw
Copy link

maciejw commented Feb 9, 2018

this does not work, its possible to write tests like this:

[1,2,3,4].map(i=> {
  it(`is dynamic test name ${i}`, ()=> {
    expect(i+5).toMatchSnapshot();
  })
});

do you think it would be hard to add support for this case?

@asvetliakov
Copy link
Owner

Hello,
This will be almost impossible without tying to jest execution to obtaining snapshot names after test run. Snapshots names are calculated by static analysis of source file, so any dynamic stuff like the one in your example won't work.

@maciejw
Copy link
Author

maciejw commented Feb 9, 2018

what if string variables ${} would be converted to whildcard, test name would be converted to

/is dynamic test name [.]+ [0-9]+/

and then on mouse over toMatchSnapshot we could display all matched snapshots?

@asvetliakov
Copy link
Owner

May be a good idea. I'll look

@asvetliakov
Copy link
Owner

Version 1.5.0 supports resolving constants in blocks, although probably this is not exactly that you've asked
Example:

import { Api } from "./api";
const A = "A";
const B = 5;

it(Api.LOGIN, () => {
   expect("Something").toMatchSnapshot();
});

it(`${Api.LOGIN} works with ${A} and ${B}`, () => {
   expect("Something").toMatchSnapshot();
});

Hope this helps

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

No branches or pull requests

2 participants