Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

strange issue where jquery .show('fast') works when called the first time but not when called again #44

Closed
structuralartistry opened this issue Jan 15, 2012 · 1 comment

Comments

@structuralartistry
Copy link

I have posted a git repo illustrating this problem. If I have a hidden element and call .show() on it and .hide() it again multiple times all my specs pass. However if I add animation such as .show('fast'), the first time is called I get the expected result but not the second time.

The repo is: https://github.com/structuralartistry/jasmine_jquery_animation_issue

The actual test code is (note that I run this code both with and without using sinon.js fake timer):

(function() {

describe('jasmine jquery with jquery animation', function() {

describe('without sinon fake timer', function() {
  // note the only difference between the two specs below is that the first uses .show() and second uses .show('fast')

  it('jquery show without animation passes on second try of same call', function() {
    var fixture_html;
    fixture_html = "<div id='selector' style='display: none'><table><tr><td id='select_option_1'>B</td></tr></table></div><table><tr><td id='button' onmousedown=\"$('#selector').show();\">Click Me</td></tr></table>";
    setFixtures(fixture_html);
    expect($('#selector')).toBeHidden();
    $('#button').mousedown();
    expect($('#selector')).toBeVisible();
    $('#selector').hide();
    expect($('#selector')).toBeHidden();
    $('#button').mousedown();
    return expect($('#selector')).toBeVisible();
  });


  it('jquery show with animation fails on second try of same call', function() {
    var fixture_html;
    fixture_html = "<div id='selector' style='display: none'><table><tr><td id='select_option_1'>B</td></tr></table></div><table><tr><td id='button' onmousedown=\"$('#selector').show('slow');\">Click Me</td></tr></table>";
    setFixtures(fixture_html);
    expect($('#selector')).toBeHidden();
    $('#button').mousedown();
    expect($('#selector')).toBeVisible();
    $('#selector').hide();
    expect($('#selector')).toBeHidden();
    $('#button').mousedown();
    // to make spec pass uncomment the below
    return expect($('#selector')).toBeVisible();
  });

});

describe('with sinon fake timer', function() {
  // note the only difference between the two specs below is that the first uses .show() and second uses .show('fast')

  it('jquery show without animation passes on second try of same call', function() {
    clock = sinon.useFakeTimers()
    var fixture_html;
    fixture_html = "<div id='selector' style='display: none'><table><tr><td id='select_option_1'>B</td></tr></table></div><table><tr><td id='button' onmousedown=\"$('#selector').show();\">Click Me</td></tr></table>";
    setFixtures(fixture_html);
    expect($('#selector')).toBeHidden();
    $('#button').mousedown();
    expect($('#selector')).toBeVisible();
    $('#selector').hide();
    expect($('#selector')).toBeHidden();
    $('#button').mousedown();
    clock.tick(5000)
    expect($('#selector')).toBeVisible();
    return clock.restore()
  });


  it('jquery show with animation fails on second try of same call', function() {
    clock = sinon.useFakeTimers()
    var fixture_html;
    fixture_html = "<div id='selector' style='display: none'><table><tr><td id='select_option_1'>B</td></tr></table></div><table><tr><td id='button' onmousedown=\"$('#selector').show('slow');\">Click Me</td></tr></table>";
    setFixtures(fixture_html);
    expect($('#selector')).toBeHidden();
    $('#button').mousedown();
    expect($('#selector')).toBeVisible();
    $('#selector').hide();
    expect($('#selector')).toBeHidden();
    $('#button').mousedown();
    clock.tick(5000)
    // to make spec pass uncomment the below
    expect($('#selector')).toBeVisible();
    return clock.restore()
  });

});

});

}).call(this);

@travisjeffery
Copy link
Collaborator

You mind making a branch including the failing tests that I can easily run if this is still an issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants