Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow taking class names in describe #5152

Closed
JoshuaKGoldberg opened this issue Dec 21, 2017 · 1 comment
Closed

Allow taking class names in describe #5152

JoshuaKGoldberg opened this issue Dec 21, 2017 · 1 comment

Comments

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Dec 21, 2017

Suppose you have a class under test:

class Adder {
    add(a, b) {
        return a + b;
    }
}

...and a describe block of tests:

describe("Adder", () => {
    it("adds two numbers", () => {
        expect(new Adder().add(1, 2)).toBe(2);
    });
});

If Adder is renamed, refactoring tools won't generally catch that the string in the test file should also be updated. We'd have to do that manually. ☹️

A solution to this could be to allow taking class/function names instead of the string. On environments that support it, there's a .name property string that can be used directly. On environments that don't (IE!), it can be parsed from the function name.

describe(Adder, () => {
    it("adds two numbers", () => {
        expect(new Adder().add(1, 2)).toBe(2);
    });
});
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants