Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Textinput: Only _destroy() clearButton when present #7568

Closed
wants to merge 3 commits into from

Conversation

gabrielschulhof
Copy link

Fixes gh-7567

@@ -149,4 +149,35 @@
"turning off clearBtn removes wrapper class 'ui-input-has-clear'" );
});

( function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this in its own iife?

Copy link
Author

Choose a reason for hiding this comment

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

Well, mostly because I declare variables that are relevant only to the test that follows. I'd hate to have to declare those variables at the top of the file (as per our style guide), because having them placed so far away from where they're actually used is confusing. However, it's not just for aesthetics. The scoping reflects the fact that the module setup/teardown is not enough to actually gather the information that I need.

deepEqual( $.testHelper.domEqual( originalDOM, $( "#destroy-test-container" ) ), true,
"Original DOM is restored after textinput destruction" );

deepEqual( destroyClearCalled, false, "_destroyClear() was not called" );
Copy link
Contributor

Choose a reason for hiding this comment

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

This test does not really make sense it cant possibly run AND evaluate to true because there will be a failure because of the error being thrown.

Copy link
Author

Choose a reason for hiding this comment

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

OK, I totally misread your comment here. I thought you did not want me to let the exception bubble up to qunit and have the test fail that way.

There is still a good reason to ensure that _destroyClear() does not get called. If a text input does not have a clear button, _destroyClear() should not get called, whether it throws an exception or not. So, I think the second assertion is justified.

If you accept this line of reasoning, I'll restore this test and delete the one below.

test( "textinput destruction does not throw error", function() {
var errorThrown;

try {
Copy link
Contributor

Choose a reason for hiding this comment

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

QUnit already does a try catch there is no need to test for errors in tests. If an error is triggered the tests will fail and it will be caught by qunit

@arschmitz arschmitz removed their assignment Aug 26, 2014
@gabrielschulhof
Copy link
Author

@arschmitz I've answered your comment on the outdated diff because that version of the test may be the way to go after all.

Argh! To see the outdated diff click on the link above, then go to the location and hit Enter, otherwise you won't see the actual diff and the discussion.

@arschmitz
Copy link
Contributor

@gabrielschulhof you don't need to test that the method is not called or catch any errors just test destroy on a textarea and an input with out a clearbutton if you don't get an error its not called. If you get an error the test fails.

@gabrielschulhof
Copy link
Author

OK. Gotcha. In that case, the destroy test alone should suffice.

@gabrielschulhof gabrielschulhof force-pushed the 7567-fix-textinput-destroy branch from a11be3f to f31a93a Compare August 27, 2014 19:30
@@ -127,7 +127,9 @@ define( [

_destroy: function() {
this._super();
this._destroyClear();
if ( this.options.clearBtn && !this.options.enhanced ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We still do normal destroy when enhanced is true

Copy link
Author

Choose a reason for hiding this comment

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

Riiight! True!

Copy link
Author

Choose a reason for hiding this comment

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

Wait ... I don't get it. I call super() ... let's talk on IRC ...

@arschmitz
Copy link
Contributor

👍

gabrielschulhof pushed a commit that referenced this pull request Sep 4, 2014
@gabrielschulhof gabrielschulhof deleted the 7567-fix-textinput-destroy branch September 4, 2014 20:28
agcolom pushed a commit to agcolom/jquery-mobile that referenced this pull request Nov 26, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Textinput: Throws error upon destroy
3 participants