asvetliakov / typescript-snapshots-plugin

Snapshots language service support for Typescript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dynamic test name

maciejw opened this issue · 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?

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.

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?

May be a good idea. I'll look

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