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

[Feature request] Could see the original line of assert statement #3715

Closed
Albert-Gao opened this issue Jun 2, 2017 · 4 comments
Closed

Comments

@Albert-Gao
Copy link

Do you want to request a feature or report a bug?
I want to request a feature

What is the current behavior?

test('Should return jwt after successfully registration', async () => {
        await removeTestUser();
        const response = await request(app).post(signupAPI).send(testUser);
        expect(response.statusCode).toBe(200);
        expect(response.body).not.toHaveProperty('error');
        expect(response.body).toHaveProperty('user');
        expect(response.body.user.name).toBeDefined();
        expect(response.body.user.email).toBeDefined();
        expect(response.body.user.token).toBeDefined();
        await removeTestUser();
    });

I use supertest + jest to test my express.js application, all use the latest version.
The test runs fine. The problem is, if there is anything wrong, the output would be:

 ● [API Test] /api/auth/register › Should return jwt after successfully registration

    expect(received).toBeDefined()
    
    Expected value to be defined, instead received
      undefined
      
      at _callee8$ (tests/backend/integration/signup.test.js:98:57)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:65:40)

Some situation like this, If the value is undefined,
And I happen to have multiple same assert,
There is no way to see the reason in the bash,
I need to track back to the file to see which line threw the error.
Yes, I should track back, but wouldn't it better to show a result like below:

What is the expected behavior?

 ● [API Test] /api/auth/register › Should return jwt after successfully registration

    expect(response.body.user.name).toBeDefined()
    
    Expected response.body.user.name to be defined, instead received
      undefined
      
      at _callee8$ (tests/backend/integration/signup.test.js:98:57)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:65:40)

Thanks :) Love jest.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

{
  "verbose": true,
  "rootDir": "../",
  "testPathIgnorePatterns": ["<rootDir>/node_modules/", "<rootDir>/tests/acceptance/", "<rootDir>/tests/coverageReport/", "<rootDir>/dist/"],
  "collectCoverage": false,
  "coverageDirectory": "tests/coverageReport",
  "collectCoverageFrom" : ["**/src/**"],
  "coveragePathIgnorePatterns": ["<rootDir>/node_modules/", "<rootDir>/configs/", "<rootDir>/src/config/appconfig.json", "<rootDir>/dist/"],
  "coverageReporters": ["text", "text-summary"]
}
@thymikee
Copy link
Collaborator

Jest now only has access to a value carried by response.body.user.name, that's why it shows generic message. Wonder how we could make it better.

@kimjoar
Copy link
Contributor

kimjoar commented Jun 11, 2017

Maybe it's possible to do something along the lines of Ava, which displays the code around the failed assertion?

ava

See e.g. https://github.com/avajs/ava#magic-assert and https://github.com/avajs/ava#snapshot-testing

@SimenB
Copy link
Member

SimenB commented Dec 15, 2017

EDIT: I misunderstood the issue - you want more info on what failed without having to look up the code manually, that's tracked in #3415

@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.
Projects
None yet
Development

No branches or pull requests

4 participants