typescript-snapshots-plugin icon indicating copy to clipboard operation
typescript-snapshots-plugin copied to clipboard

dynamic test name

Open maciejw opened this issue 8 years ago • 4 comments

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?

maciejw avatar Feb 09 '18 13:02 maciejw

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.

asvetliakov avatar Feb 09 '18 18:02 asvetliakov

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?

maciejw avatar Feb 09 '18 19:02 maciejw

May be a good idea. I'll look

asvetliakov avatar Feb 09 '18 20:02 asvetliakov

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

asvetliakov avatar Oct 15 '18 12:10 asvetliakov