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

Made operator property on errors optional. #41

Merged
merged 1 commit into from
Aug 7, 2020
Merged

Made operator property on errors optional. #41

merged 1 commit into from
Aug 7, 2020

Conversation

loucyx
Copy link
Contributor

@loucyx loucyx commented Aug 7, 2020

If I just do inside a test:

throw Error("Mesage");

I get this:

Message  (undefined)

Followed by the stack trace, instead of just getting Message. This is because the format function is expecting the error to have a string property operator to put after the message of the error.

This MR makes it so if that property is missing, we just skip it.

@codecov-commenter
Copy link

codecov-commenter commented Aug 7, 2020

Codecov Report

Merging #41 into master will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #41   +/-   ##
=======================================
  Coverage   90.06%   90.06%           
=======================================
  Files           3        3           
  Lines         302      302           
=======================================
  Hits          272      272           
  Misses         30       30           
Impacted Files Coverage Δ
src/index.js 78.09% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2bc0026...e21d258. Read the comment docs.

Copy link
Owner

@lukeed lukeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey~! How do you feel about (unknown) instead?

@loucyx
Copy link
Contributor Author

loucyx commented Aug 7, 2020

@lukeed I still feel is "adding stuff" to my error message, but is better than (undefined) for sure!

@lukeed
Copy link
Owner

lukeed commented Aug 7, 2020

Ok. Can you please "allow edits from maintainers" so that I can push a commit?

@loucyx
Copy link
Contributor Author

loucyx commented Aug 7, 2020

For some reason I can find the option to allow edits from maintainer (and I think is because of this). I'll try adding you as maintainer to the fork I did.

@lukeed
Copy link
Owner

lukeed commented Aug 7, 2020

No problem. Can you please insert this for the entire format function?

function format(name, err, suite = '') {
	let { details, operator='' } = err;
	let idx = err.stack && err.stack.indexOf('\n');
	if (err.name.startsWith('AssertionError') && !operator.includes('not')) details = compare(err.actual, err.expected); // TODO?
	let str = '  ' + FAILURE + (suite ? kleur.red(SUITE(` ${suite} `)) : '') + ' ' + QUOTE + kleur.red().bold(name) + QUOTE;
	str += '\n    ' + err.message + (operator ? kleur.italic().dim(`  (${operator})`) : '') + '\n';
	if (details) str += GUTTER + details.split('\n').join(GUTTER);
	if (!!~idx) str += stack(err.stack, idx);
	return str + '\n';
}

@loucyx
Copy link
Contributor Author

loucyx commented Aug 7, 2020

Sure thing!

Copy link
Owner

@lukeed lukeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@lukeed lukeed merged commit 18ada58 into lukeed:master Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants