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

Testing Strangeness using Ember Qunit and Test Helpers #63

Closed
jnhuynh opened this issue Jun 6, 2014 · 4 comments
Closed

Testing Strangeness using Ember Qunit and Test Helpers #63

jnhuynh opened this issue Jun 6, 2014 · 4 comments

Comments

@jnhuynh
Copy link

jnhuynh commented Jun 6, 2014

I have a test that passes and then upon refresh fails with a unhelpful error. If I run the test by itself, it always passes.

I am not sure if this issue falls under Ember-qunit, Ember-cli, EmberJs. This is a boiler plate Ember-cli project, I am running Ember-cli version 0.0.28.

Am I missing something or is this a bug?

This is the error:

screen shot 2014-06-05 at 10 28 35 pm

I know that the code works through manual testing. My Tournament model hasMany('competitor'). I have the appropriate Competitor model.

Also, the screen shot below will show that all of my selectors are correct.

screen shot 2014-06-05 at 10 32 40 pm

This is the integration test:

import { test } from 'ember-qunit';
import startApp from 'scratch-masters/tests/helpers/start-app';

var App;

module('Integration - Competitors Management', {
  setup: function() {
    App = startApp();
  },

  teardown: function() {
    Ember.run(App, App.destroy);
  }
});

var competitorNameInputSelector    = 'input#new-competitor-name',
    addCompetitorButtonSelector    = 'button#add-competitor',
    removeCompetitorButtonSelector = 'button.remove-competitor',
    competitorListSelector         = 'table#competitors-list',
    competitorListItemSelector     = 'table#competitors-list tbody tr';

test('it should have UI for adding and displaying competitors', function() {
  expect(4);

  visit('/tournaments/new');

  andThen(function() {
    shouldHaveElementWithCount(competitorNameInputSelector, 1, null);
    shouldHaveElementWithCount(addCompetitorButtonSelector, 1, null);
    shouldHaveElementWithCount(competitorListSelector, 1, null);
    shouldHaveElementWithCount(competitorListItemSelector, 0, null);
  });
});

test('it should allow competitor adding', function() {
  expect(2);

  visit('/tournaments/new');
  fillIn(competitorNameInputSelector, 'Bob Saget');
  click(addCompetitorButtonSelector);

  andThen(function() {
    shouldHaveElementWithCount(competitorListItemSelector, 1, null);
  });

  fillIn(competitorNameInputSelector, 'Keanu Reeves');
  click(addCompetitorButtonSelector);

  andThen(function() {
    shouldHaveElementWithCount(competitorListItemSelector, 2, null);
  });
});

The main pieces of code that get exercised are the actions in this controller:

var TournamentsNewController = Ember.ObjectController.extend({
  newCompetitorName: '',

  actions: {
    addCompetitor: function() {
      var newCompetitorName = this.get('newCompetitorName'),
          newCompetitor;

      if (newCompetitorName) {
        newCompetitor = this.store.createRecord('competitor', {
          name: newCompetitorName
        });

        this.get('competitors').pushObject(newCompetitor);
        this.set('newCompetitorName', '');
      }
    },

    removeCompetitor: function(competitor) {
      if (competitor) {
        this.get('competitors').removeObject(competitor);
      }
    }
  }
});

export default TournamentsNewController;
@stefanpenner
Copy link
Member

@jnhuynh i believe this is a bug in ember-data + the container, but I believe @mixonic submitted a fix which is on ember-data master. Can you confirm this problem stills exists then?

@jnhuynh
Copy link
Author

jnhuynh commented Jun 6, 2014

@stefanpenner Sure thing, I'll try to retest against ember-data master and will update this issue accordingly.

@stefanpenner
Copy link
Member

@jnhuynh thanks!

@jnhuynh
Copy link
Author

jnhuynh commented Jun 6, 2014

So, I updated my bower.json to include "ember-data": "1.0.0-beta.8", ran bower install and things are working.

I am assuming 1.0.0-beta.8 is master since that's the newest I can find on bower.

Either way, my tests are now passing consistently so some something must have changed during the minor version changed. It's probably the fix from @mixonic.

I'm going to close this ticket. @stefanpenner thanks for the help. I also noticed that the latest Ember-cli already has the updated Ember-data version. I really need to update Ember-cli more frequently 😅.

@jnhuynh jnhuynh closed this as completed Jun 6, 2014
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

No branches or pull requests

2 participants