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

test(assert): increase coverage #1085

Merged
merged 1 commit into from
Mar 17, 2018
Merged

Conversation

sukrosono
Copy link
Contributor

related issue #1084

@sukrosono sukrosono requested a review from a team as a code owner November 9, 2017 10:38
@codecov
Copy link

codecov bot commented Nov 9, 2017

Codecov Report

Merging #1085 into master will increase coverage by 0.73%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1085      +/-   ##
==========================================
+ Coverage   93.61%   94.34%   +0.73%     
==========================================
  Files          32       32              
  Lines        1628     1628              
  Branches      393      393              
==========================================
+ Hits         1524     1536      +12     
+ Misses        104       92      -12
Impacted Files Coverage Δ
lib/chai/interface/assert.js 93.04% <0%> (+3.2%) ⬆️

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 f54f71c...6eb1a50. Read the comment docs.

@sukrosono sukrosono changed the title test(assert), increase coverage test(assert): increase coverage Nov 9, 2017
@sukrosono
Copy link
Contributor Author

sukrosono commented Nov 21, 2017

Since the msg is empty on changesBy, changesButNotBy, increasesBy, decreasesBy, doesNotDecreaseBy. I want to refactor them to not use tmpMsg. Please let me know if it's a wrong turn. I will only rely on travis test when refactor them.

Seems doesNotIncrease do it correctly. Since the author of #621 is @lucasfcosta, i like to listen to his opinion as well.

* Can be used to assert the inclusion of a subset of properties in an
*
* Asserts that 'haystack' includes 'needle'.
* Can be used to assert the inclusion of a subset of properties in an
Copy link
Contributor Author

Choose a reason for hiding this comment

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

trailing space are removed by atom i guest. Would this affect documentation? If yes i will carefully add space on every next line. So next line will be *<space><space>...

Copy link
Member

Choose a reason for hiding this comment

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

Well, I would not worry about this that much even though we've already got #1042.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, the overall explanation make it clearer. I will process when i had chance 😄 , glad to see you back. 💌

test/assert.js Outdated
assert.changesButNotBy(fnDec, obj, 'value', 1);
// assert.changesButNotBy(fnDec, getterFn, 'value', 1);
Copy link
Member

Choose a reason for hiding this comment

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

Why are these assertions commented out? Do they not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes Cap, it doesn't work. That's why i made #1090 , 😄

Copy link
Member

@lucasfcosta lucasfcosta left a comment

Choose a reason for hiding this comment

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

Hi @brutalcrozt,

First of all, I'd like to thank you for this PR! ❤️

However, I don't think these changes are compatible with our intentions with the changes/increases/decreases API.

There has been a misunderstanding.

As I've commented in my review, when providing a prop and a function we will end up checking for that prop in the function object. This is how the API is supposed to work.

If we've already got a getterFn then we don't need to specify any keys and it would not allow us to check for properties in functions.

msg = tmpMsg;
prop = null;
Copy link
Member

Choose a reason for hiding this comment

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

I think this is not correct.

When we have four arguments and the type of obj is a function, we cannot set prop to null because the user might desire to check for the value of a prop in a function, since a function in JavaScript can have properties.

Please correct me if I'm wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will try to exclude this commit, focusing on testing only. Either we both wrong or none of us is wrong.

delta = prop;
msg = tmpMsg;
msg = 'getter function';
prop= null;
Copy link
Member

Choose a reason for hiding this comment

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

Same here, if we have four arguments to this I think that prop must not be null.

Also, a space is missing between prop and the = sign.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OMG, he notice 😄 , indeed that's my mistake. Did we need eslint?

* Can be used to assert the inclusion of a subset of properties in an
*
* Asserts that 'haystack' includes 'needle'.
* Can be used to assert the inclusion of a subset of properties in an
Copy link
Member

Choose a reason for hiding this comment

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

Well, I would not worry about this that much even though we've already got #1042.

test/assert.js Outdated
bangFn = function() { obj.str += '!' },
smFn = function() { 'foo' + 'bar' },
batFn = function() { heroes.push('batman') },
lenFn = function() { return heroes.length };

assert.changes(fn, obj, 'value');
assert.changes(fn, getterFn, 'value');
Copy link
Member

Choose a reason for hiding this comment

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

I also think that this is incorrect.

When writing assert.changes(fn, getterFn, 'value') I understand that you expect fn to change the property value of getterFn.

It's redundant to specify a key if you already have a getter function. If we did this it would not be possible to check for property in function objects as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the misunderstanding is located here.

I found it awkward when we use assert(fn, getterFn, null, 1);

Which should be assert.changesBy(fn, getterFn, deltaValue);

I will continue discussing on issue 1090, kindly re-validate with your point of view.

Copy link
Member

Choose a reason for hiding this comment

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

Hi @brutalcrozt, thanks for the answer.

I'm sorry but I still didn't understand how this could be correct, since delta cannot be a string, which is what you're passing by using 'value' as the last argument.

Can anyone else please review & confirm just for us to make sure we're not missing any detail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey brother, i think no need to ask third person point of view. I assume there is misunderstanding, i can say it correct just because run node test resulting green and travis also green. Have i show you this ?
Sorry i also make mistake again here, i mislead you. you are reviewing the assert.changes but i am comment about assert.changesBy.


I think that assert.changes pass because the key or property is be null when reaching this line.
do i need make additional change about this assert.changes ?
If you don't mind, please addressing assert.changesBy on other line. When you feel still necessary 😄 .

Copy link
Member

@lucasfcosta lucasfcosta Nov 29, 2017

Choose a reason for hiding this comment

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

Ah, I understand this now. You were right about the tests passing.

The reason why I was confused was because of this line, which uses the third argument as a message when the second one is a function and we only have three arguments.

However, would you mind just changing the value string to example message or something like that? Just to make sure the test looks clear.

Great work, btw! Thanks 😄


PS.: IMO we should change this API in the future, otherwise we will make it mandatory for users to supply a message when they want to assert on a property present in a function, which is not that uncommon.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, let me know if this still require some change.


Agreed, we should add it to next milestone. 4.2.0 ?
Kinda related to #1090, but unfortunately i still have issue to formulate the word. Let's continue there 😉

Copy link
Member

@lucasfcosta lucasfcosta left a comment

Choose a reason for hiding this comment

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

Hi @brutalcrozt, thanks for the new commits, but I've seen that you just added a revert commit to this PR, but doing so basically resets all the feature changes right? Right now we've only got test changes.

I've seen the diff and the tests look a bit confusing btw. I made specific comments on them.

Let's make sure all the code is correctly indented too.

When reverting changes I highly recommend you to use rebase instead of adding commits. Rebase allows you to make the git log look cleaner and better without adding new unnecessary commits.

This video is a great way to learn about rebase btw.

If you need any help, please let me know.

test/assert.js Outdated
@@ -2251,26 +2251,33 @@ describe('assert', function () {
heroes = ['spiderman', 'superman'],
fn = function() { obj.value += 5 },
fnDec = function() { obj.value -= 20 },
getterFn = function() { return obj.value },
getter= function() {},
Copy link
Member

Choose a reason for hiding this comment

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

Missing a space between = and the identifier.

test/assert.js Outdated
bangFn = function() { obj.str += '!' },
smFn = function() { 'foo' + 'bar' },
batFn = function() { heroes.push('batman') },
lenFn = function() { return heroes.length };

getter.value= obj.value;
Copy link
Member

Choose a reason for hiding this comment

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

Missing a space here too. But this line will probably end up being deleted due to never using getter.

test/assert.js Outdated
@@ -2251,26 +2251,33 @@ describe('assert', function () {
heroes = ['spiderman', 'superman'],
fn = function() { obj.value += 5 },
fnDec = function() { obj.value -= 20 },
getterFn = function() { return obj.value },
getter= function() {},
Copy link
Member

Choose a reason for hiding this comment

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

It also seems like this function is never used.

test/assert.js Outdated
assert.changes(fn, obj, 'value');
assert.changes(fn, getterFn, 'value');
Copy link
Member

Choose a reason for hiding this comment

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

This does not seem correct.

If we want to test properties on functions we must create an fn that changes the value of a prop in the getterFn. What you've done here is create another getter function which has a value prop that is never used.

test/assert.js Outdated
assert.changesBy(fn, obj, 'value', 5);
assert.changesBy(fn, obj, 'value', -5);
assert.changesBy(fn, getterFn, 5);
Copy link
Member

Choose a reason for hiding this comment

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

Please take a look at the comment I've made on the first assertion test because that is valid to all additions below, such as this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so basically resets all the feature changes right?

Yes, sir.

Let's make sure all the code is correctly indented too.

Agreed.


Sorry that i have made unnecessary notification and work for you. I already take a look at your slack status about 5-10 min, because i already had bad experience with git rebase. So i ask Keith instead, but still i get lost on my own confusion. With your aid i found some clarity, but it seems i found it while you do the last review.

Due to unexpected rain, i made those dirty line. I have to save really quick and forgot to clean up, i will make sure it won't happen again. I will watch video that you mention, when i get lost again about git rebase.1. I am also not sure are you still busy on real world or not 2. Based on previous response time, i assume that this PR will get a bit of delay. Somehow i miss your last review on this PR.

I really felt bad about this, hope on tomorrow. It should bring fresh state.

Copy link
Member

Choose a reason for hiding this comment

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

Hey buddy, there's no need to feel bad about it. We're very happy that you want to contribute. Please don't worry about that 😃

Basically, when doing a rebase -i you will be prompted with a list of commits and a few actions to do with them.

Whenever you want to drop a commit you can just use the drop word in front of it.

In order to ammend a commit into the last one you can use fixup and you can also use squash to ammend commits and change their messages as well.

After doing it a few times you will see it's simple, you just gotta try, it's totally normal to make mistakes the first times you try it.

@lucasfcosta
Copy link
Member

I got it now, I just had a minor comment about the value string.

Also, IMO we should change this API in the future to make it more consistent. I think that checking props on functions is a valid and not uncommon use case and therefore should be supported on this interface in the same way it is supported on the others.

Right now we need to pass a message that is truthy in order to do that in this interface.

@sukrosono sukrosono force-pushed the patch-coverage branch 2 times, most recently from 567ff6d to 36a455d Compare December 13, 2017 17:02
@sukrosono
Copy link
Contributor Author

sukrosono commented Dec 13, 2017

😄 ahh a burst of happiness. Finally i got the point of rebase, also i can address my own misunderstanding.
Thanks for being patient 💘

I got minor curiosity, kindly someone answer it:

  • commit msg that i made via web interface (c1) is different with commit msg that i made on rebase (c2). Which thing is affected by c1 and c2?
  • what is saved on history is c2 right? what i mean is on git log

@lucasfcosta
Copy link
Member

@brutalcrozt I'm afraid I won't be able to help regarding that since I don't use the web interface.

I'm also not sure I understand your question correctly.

But please make sure to check your git configurations. If you take a look at your commit you will be able to see that it contains an invalid-mail-address as one of the committers. Maybe this link can help you.

@sukrosono
Copy link
Contributor Author

Nvm, the question is not really important.
Is it the reason you don't approve it?
As I remember the first commit is when I use live CD OS. I am in a rush so not configure the email properly.
I am not sure I know how to change the first commit email. Should I reopen new PR instead? 😉

@lucasfcosta
Copy link
Member

@sukrosono
Copy link
Contributor Author

Okay, now it's green? 😍 . Thanks for believe in me.

@lucasfcosta
Copy link
Member

Yay! You're almost there buddy, you just gotta change the commit message following these guidelines: https://conventionalcommits.org/

  - on changes, decreases and increases family
@sukrosono
Copy link
Contributor Author

done

Copy link
Contributor

@meeber meeber left a comment

Choose a reason for hiding this comment

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

Awesome work @brutalcrozt and @lucasfcosta. This LGTM.

Copy link
Member

@astorije astorije left a comment

Choose a reason for hiding this comment

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

Nice work! Will let @lucasfcosta review and merge if he's happy :)

@meeber
Copy link
Contributor

meeber commented Jan 17, 2018

@lucasfcosta Any chance you could take a look at this? You have an open review blocking merge :D

@lucasfcosta
Copy link
Member

Oh, I'm so sorry I missed this for so long!

@lucasfcosta lucasfcosta merged commit 11612e9 into chaijs:master Mar 17, 2018
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.

5 participants