This commit is contained in:
Sidharth Vinod 2022-09-07 18:04:43 +05:30
parent 5905787bea
commit 407927c8ec
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD
2 changed files with 28 additions and 3 deletions

View File

@ -27,7 +27,7 @@ describe('when using the ganttDb', function () {
${'1f'} | ${moment.duration.invalid()} ${'1f'} | ${moment.duration.invalid()}
` `
)('should $str resulting in $expected duration', ({ str, expected }) => { )('should $str resulting in $expected duration', ({ str, expected }) => {
expect(ganttDb.parseDuration(str).toString()).not.toEqual(expected); expect(ganttDb.parseDuration(str)).toEqual(expected);
}); });
}); });

View File

@ -1,6 +1,31 @@
/* /*
* Used to convert Tagged Template literals to object arrays as required by vitest. Used to convert jest's Tagged Template literals to object arrays as required by vitest.
Example:
Jest code
```ts
it.each`
str | expected
${'1d'} | ${moment.duration(1, 'd')}
${'2w'} | ${moment.duration(2, 'w')}
`('should parse $str to $expected duration', ({ str, expected }) => {
expect(yourFunction(str)).toEqual(expected);
});
```
Vitest code
```ts
it.each(convert`
str | expected
${'1d'} | ${moment.duration(1, 'd')}
${'2w'} | ${moment.duration(2, 'w')}
`)('should parse $str to $expected duration', ({ str, expected }) => {
expect(yourFunction(str)).toEqual(expected);
});
```
*/ */
export const convert = (template: TemplateStringsArray, ...params: any[]) => { export const convert = (template: TemplateStringsArray, ...params: any[]) => {
const header = template[0] const header = template[0]
.trim() .trim()