Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
aaa42ab56b fix(types): allow test.todo and describe.todo to accept single string argument
The documentation shows test.todo("description") with a single argument,
but the type definitions required a callback function as the second argument.
This caused TypeScript error TS2554 when following the documentation.

This fix adds TestTodo and DescribeTodo interfaces that support both:
- Single argument: test.todo("unimplemented feature")
- With callback: test.todo("feature", () => { ... })

Fixes #25959

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 09:59:33 +00:00
2 changed files with 96 additions and 5 deletions

View File

@@ -206,6 +206,32 @@ declare module "bun:test" {
type DescribeLabel = number | string | Function | FunctionLike;
/**
* Marks a group of tests as to be written or to be fixed.
*
* When called with only a label, creates a placeholder test group that will be
* shown in test results as "todo". When called with both a label and a function,
* the tests will not be executed unless the `--todo` flag is passed.
*
* @example
* // Placeholder test group - just a label
* describe.todo("unimplemented feature group");
*
* // Test group with implementation that won't run by default
* describe.todo("feature group to fix", () => {
* test("broken test", () => {
* expect(broken()).toBe(true);
* });
* });
*
* @param label the label for the tests
* @param fn optional function that defines the tests
*/
export interface DescribeTodo<T extends Readonly<any[]>> {
(label: DescribeLabel): void;
(label: DescribeLabel, fn: (...args: T) => void): void;
}
/**
* Describes a group of related tests.
*
@@ -238,8 +264,12 @@ declare module "bun:test" {
skip: Describe<T>;
/**
* Marks this group of tests as to be written or to be fixed.
*
* When called with only a label, creates a placeholder test group that will be
* shown in test results as "todo". When called with both a label and a function,
* the tests will not be executed unless the `--todo` flag is passed.
*/
todo: Describe<T>;
todo: DescribeTodo<T>;
/**
* Marks this group of tests to be executed concurrently.
*/
@@ -442,6 +472,39 @@ declare module "bun:test" {
type Flatten<T, Copy extends T = T> = { [Key in keyof T]: Copy[Key] };
}
/**
* Marks a test as to be written or to be fixed.
*
* When called with only a test name, creates a placeholder test that will be
* shown in test results as "todo". When called with both a name and a function,
* the test will not be executed unless the `--todo` flag is passed.
*
* @example
* // Placeholder test - just a name
* test.todo("unimplemented feature");
*
* // Test with implementation that won't run by default
* test.todo("feature to fix", () => {
* expect(broken()).toBe(true);
* });
*
* @param label the label for the test
* @param fn optional test function
* @param options optional test timeout or options
*/
export interface TestTodo<T extends ReadonlyArray<unknown>> {
(label: string): void;
(
label: string,
fn: (
...args: __internal.IsTuple<T> extends true
? [...table: __internal.Flatten<T>, done: (err?: unknown) => void]
: T
) => void | Promise<unknown>,
options?: number | TestOptions,
): void;
}
/**
* Runs a test.
*
@@ -495,12 +558,13 @@ declare module "bun:test" {
/**
* Marks this test as to be written or to be fixed.
*
* These tests will not be executed unless the `--todo` flag is passed. With the flag,
* When called with only a test name, creates a placeholder test that will be
* shown in test results as "todo". When called with both a name and a function,
* the test will not be executed unless the `--todo` flag is passed. With the flag,
* if the test passes, the test will be marked as `fail` in the results; you will have to
* remove the `.todo` or check that your test
* is implemented correctly.
* remove the `.todo` or check that your test is implemented correctly.
*/
todo: Test<T>;
todo: TestTodo<T>;
/**
* Marks this test as failing.
*

View File

@@ -0,0 +1,27 @@
import { describe, expect, test } from "bun:test";
// https://github.com/oven-sh/bun/issues/25959
// test.todo and describe.todo should accept a single string argument
// Test.todo with single argument - the reported issue
test.todo("unimplemented feature");
// Test.todo with callback - should still work
test.todo("feature with callback that would fail", () => {
expect(1).toBe(2);
});
// describe.todo with single argument
describe.todo("unimplemented feature group");
// describe.todo with callback - should still work
describe.todo("feature group with callback", () => {
test("nested test that would fail", () => {
expect(1).toBe(2);
});
});
// Regular test to make the file run
test("this test passes", () => {
expect(true).toBe(true);
});