mercredi 20 janvier 2016

Ember integration tests failing when running multiple at once

I've run into a weird problem writing integration tests for my component. When I run each one individually, they pass. When I run multiple, the first one passes and the other ones fail. I think it has something to do with closure actions but I don't know.

Here's my component code

// components/game-nav-key.js
triggerKeyAction(code) {
  if (this.get('prevKeyCode').contains(code)) {
    this.sendAction('onPrevKey', true);
  } else if (this.get('nextKeyCode').contains(code)) {
    this.sendAction('onNextKey', true);
  } else if (this.get('openKeyCode').contains(code)) {
    this.sendAction('onOpenKey');
  }
},

didInsertElement() {
  var self = this;

  Ember.$('body').keydown(function(e) {
    self.triggerKeyAction(e.which);
  });

  Ember.$('body').keyup(function(e) {
  });
}

And my tests

// game-nav-key-test.js
it('tracks key commands and sends an action for K', function() {
  let spy = sinon.spy();
  this.set('gotoPrev', spy);
  this.render(hbs`
    {{game-nav-key onPrevKey=(action gotoPrev)}}
  `);

  triggerKeydown($('body'), 75);
  triggerKeyup($('body'), 75);

  sinon.assert.calledOnce(spy);
  sinon.assert.calledWith(spy, true);
});

it('tracks key commands and sends an action for J', function() {
  let spy = sinon.spy();
  this.set('gotoNext', spy);
  this.render(hbs`
    {{game-nav-key onNextKey=(action gotoNext)}}
  `);

  triggerKeydown($('body'), 74);
  triggerKeyup($('body'), 74);

  sinon.assert.calledOnce(spy);
  sinon.assert.calledWith(spy, true);
});

it('tracks key commands and sends an action for R', function() {
  let spy = sinon.spy();
  this.set('open', spy);
  this.render(hbs`
    {{game-nav-key onOpenKey=(action open)}}
  `);

  triggerKeydown($('body'), 82);
  triggerKeyup($('body'), 82);

  sinon.assert.calledOnce(spy);
  sinon.assert.calledWith(spy, true);
});

I removed all beforeEach's, so it's literally just those three tests. Like I said, each one passes individually, and when it is listed first, but the second two fail when run together.




Aucun commentaire:

Enregistrer un commentaire