import {expectType} from 'tsd';
import type {ExecutionContext} from '../../entrypoints/main.mjs';
import test from '../../entrypoints/main.mjs';
{
const hasLength = test.macro<[string, number]>((t, input, expected) => {
expectType<string>(input);
expectType<number>(expected);
t.is(input, expected);
});
test('bar has length 3', hasLength, 'bar', 3);
}
{
const hasLength = test.macro<[string, number]>({
exec(t, input, expected) {
expectType<string>(input);
expectType<number>(expected);
t.is(input, expected);
},
title(_providedTitle, input, expected) {
expectType<string>(input);
expectType<number>(expected);
return 'title';
},
});
test('bar has length 3', hasLength, 'bar', 3);
}
{
const hasLength = test.macro((t, input: string, expected: number) => {
t.is(input, expected);
});
test('bar has length 3', hasLength, 'bar', 3);
}
{
const hasLength = test.macro({
exec(t, input: string, expected: number) {
t.is(input, expected);
},
title(_providedTitle, input: string, expected: number) {
expectType<string>(input);
expectType<number>(expected);
return 'title';
},
});
test('bar has length 3', hasLength, 'bar', 3);
}
{
const hasLength = test.macro((t, input, expected) => {
expectType<unknown>(input);
expectType<unknown>(expected);
t.is(input, expected);
});
test('bar has length 3', hasLength, 'bar', 3);
}
{
const hasLength = test.macro<[string, number]>((t, input, expected) => {
t.is(input, expected);
});
test(hasLength, 'bar', 3);
}
{
const pass = test.macro<[]>({
exec(_t, ...args) {
expectType<[]>(args);
},
title(providedTitle, ...args) {
expectType<string | undefined>(providedTitle);
expectType<[]>(args);
return '';
},
});
test(pass);
}
{
const hasLength = (t: ExecutionContext, input: string, expected: number) => {
t.is(input.length, expected);
};
test('bar has length 3', hasLength, 'bar', 3);
}
test('has length 3 (explicit)', (t: ExecutionContext, input: string, expected: number) => {
t.is(input, expected);
}, 'bar', 3);
test('has length 3 (inferred)', (t, input, expected) => {
expectType<string>(input);
expectType<number>(expected);
t.is(input, expected);
}, 'foo', 3);
test.skip('skip', (t, input, expected) => {
expectType<string>(input);
expectType<number>(expected);
t.is(input, expected);
}, 'foo', 3);