-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
unhelpful error stack from expectationResultFactory stackFormatter #3839
Comments
Are you able to reproduce the issue on a clean repository, so we can work on proper fix? |
oh yeah. I've seen this happen before, i'm still not sure when exactly this happens and what's causing it, since most of the time we still have stack traces. |
Yes its pretty annoying.. |
@thymikee I might be able to set up a reproductional repo. Let's see if I can. So yeah, it's here: https://github.com/capaj/jest-stackFormatter-error just clone, run jest and you'll get the mysterious error. |
I'm having the same issue, using EDIT: Turns out it was due to using Axios, and the default Jest environment is not |
Getting a variant of this -
In otherwise passing tests... works fine with 20, upgrading to 21 and these have started dropping all over. These are tests using supertest on top of express, they are all responses with errors (which are what is being tested), with the call provoking the error occurring in the beforeAll() function. What fixed this for me : Changing from the callback style beforeAll((done) => {
status = jest.spyOn(express.response, 'status');
render = jest.spyOn(express.response, 'render');
mock_logger = jest.fn();
jest.mock('../../../app/util/logger', () => mock_logger);
app = express();
router = require('../../../app/routes/error');
app.set('view engine', 'html');
app.use('/', () => { throw new Error('mock error!'); });
app.use(router);
return request(app).get('/').then(done);
}); To the promise style beforeAll(() => {
status = jest.spyOn(express.response, 'status');
render = jest.spyOn(express.response, 'render');
mock_logger = jest.fn();
jest.mock('../../../app/util/logger', () => mock_logger);
app = express();
router = require('../../../app/routes/error');
app.set('view engine', 'html');
app.use('/', () => { throw new Error('mock error!'); });
app.use(router);
return request(app).get('/');
}); |
same problem for me, did someone found a workaround? |
@thymikee @aaronabramov The problem seems to be using
give the error:
but if
it give the same warnings as when using
edit: fix copy-paste of error message |
Getting the same behaviour as @awilkins and @dfroger - except I can't use the workaround, because the library I'm testing uses just callbacks. Started occurring upon upgrading jest: - "jest": "^20.0.4",
+ "jest": "^21.2.1", Thus is seems like a bug has been introduced, so I think the Enhancement label really should be changed to the Bug label @thymikee . |
I'm also having the error:
Everytime something fails in tests. That's so much annoying since every time there is something to be fixed I need to wrap all logic inside a try/catch statement. Are there any workarounds? |
That's because you're doing @capaj's example (if upgraded to jest 22) now fails looking like this: Which is better, but not good. It at least points to jsdom, which as mentioned is the issue - you need to run the test in The full, unfiltered stack is this, but I don't think it's more useful than what we give you now:
Better stack traces from async tests are tracked in #5104 |
@SimenB No, actually this is my code: That code gives me the error:
|
Hmm, OK. Can you provide a reproduction repo? Your issue is different than the OP and the last message before yours. |
Repository is private (work issues). However I can give you all pieces..
In fact I have TypeScript code that gets compiled into This is an example snippet that gives the problem: import * as Logger from "bunyan";
import { execFile as execFileWithCb, exec as execWithCb } from "child_process";
export function execFile(
programName: string,
args: Array<string>,
options?: any,
): Promise<
| { error: Error; stdout: string | Buffer; stderr: string | Buffer }
| { stdout: string | Buffer; stderr: string | Buffer }
> {
return new Promise((resolve, reject) => {
execFileWithCb(programName, args, options, (error, stdout, stderr) => {
if (error) {
reject({ error: error, stdout: stdout, stderr: stderr });
} else {
resolve({ stdout: stdout, stderr: stderr });
}
});
});
}
export function exec(
command: string,
options?: any,
): Promise<
| { error: Error; stdout: string | Buffer; stderr: string | Buffer }
| { stdout: string | Buffer; stderr: string | Buffer }
> {
return new Promise((resolve, reject) => {
execWithCb(command, options, (error, stdout, stderr) => {
if (error) {
reject({ error: error, stdout: stdout, stderr: stderr });
} else {
resolve({ stdout: stdout, stderr: stderr });
}
});
});
}
describe("UserModel", () => {
let logger: Logger;
beforeEach(async () => {
logger = await createLogger(); // Function that creates the logger, this doesn't give any error
await execFile("npm", ["run", "jdwqiwqdoiwqjoidwqj"]); // This is supposed to be a command that fails
}); |
Your issue is
When tests reject, or |
@SimenB You're right!! Thanks very much 😄 |
For your concrete use case of using |
I discovered this independently this week. Wish I had read this thread before banging my head into it. To summarize/recap, for anyone who doesn't want to read the whole thread: calling As far as a solution... the |
Sorry you're having issues! The done case can probably be fixed quite easily as you mention. For promise we can at least point back to the originating test, in addition to a message. We have the location of all tests in the results object behind a flag (https://facebook.github.io/jest/docs/en/cli.html#testlocationinresults) - we can ask the user to provide the flag and rerun the test for us to have it available. |
Fwiw I think the both cases already points to the right test. So the only
improvement for promises is to give a better error message.
…On Sat, Feb 10, 2018, 3:24 AM Simen Bekkhus ***@***.***> wrote:
The done case can probably be fixed quite easily as you mention.
For promise we can at least point back to the originating test, in
addition to a message. We have the location of all tests in the results
object behind a flag (
https://facebook.github.io/jest/docs/en/cli.html#testlocationinresults) -
we can ask the user to provide the flag and rerun the test for us to have
it available.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3839 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABBndwwS7XGXto6bzBrs5bSdn_JdiQj1ks5tTXx5gaJpZM4N8mLV>
.
|
Same here, everything reasonably up to date.. |
PR welcome improving the message! |
The PR can probably be just this commit jasmine/jasmine@8807bbb#diff-f41e57b2889bae3046aa9f352699785c I'm completely new to this codebase - I assume there's an excellent reason for forking jasmine, so I wonder if there's documentation of the changes and perhaps a best practice for importing improvements? |
It can be ported ish. Reason of forking is discussed here: https://facebook.github.io/jest/blog/2017/05/06/jest-20-delightful-testing-multi-project-runner.html#breaking-changes and here: #3147 |
|
I had this problem. It happent in my case, cause i was trying to throw an error when it was a promise and i should use returns({error:true}) instead |
Upgrading to |
Looks like
|
Jest 23 has been released as stable about a month ago, does it have the same issue? EDIT: Also, |
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. |
I have got an error from jest which leaves me blind to the actual problem that caused it:
Is it really necessary to create a new error there? Syntax error should always contain a line and collumn so couldn't jest just pass that?
https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/expectationResultFactory.js#L30
My node: 8.1.0
My jest: 20.0.4
EDIT:I've since took all of the code out of a test and run it inside babel-node. This error is the one that was swallowed:
It's really a shame when the only way to debug a failing jest test is to rewrite the test in raw node.js
The text was updated successfully, but these errors were encountered: