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

handleFindAll does not work and makeList works #111

Closed
GCorbel opened this issue Jul 27, 2015 · 6 comments
Closed

handleFindAll does not work and makeList works #111

GCorbel opened this issue Jul 27, 2015 · 6 comments

Comments

@GCorbel
Copy link

GCorbel commented Jul 27, 2015

Hi,

I have this route :

import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    return this.store.findAll('skill');
  }
});

And this test :

import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'social-learning/tests/helpers/start-app';
import TestHelper from 'ember-data-factory-guy/factory-guy-test-helper';

var application;

module('Acceptance | show the list of skills', {
  beforeEach: function() {
    application = startApp();
  },

  afterEach: function() {
    Ember.run(application, 'destroy');
  }
});

test('Show the list of skills', function(assert) {
  visit('/skills');
  TestHelper.handleFindAll('skill', 2);

  andThen(function() {
    assert.equal(find('.skill').length, 2);
    assert.equal(currentURL(), '/skills');
  });
});

When I run it, I have this result :

Acceptance | show the list of skills: Show the list of skills
    ✘ failed
         expected 2
         actual 1
MOCK GET: http://localhost:3000/api/v1/skills

It's the same result when I don't mock the http request. When I use FactoryGuy.makeList('skill', 2);, it works.

Did I do something wrong?

@FilmKnurd
Copy link

Do you need to register the request (handleFindAll) before visiting the route?

@danielspaniel
Copy link
Collaborator

That is interesting .. is this test showing that the handleFindAll('skills', 2) is only making 1 skill .. that is highly irregular and suggests a fairly drunk test helper. I will keep the liquor off the shelves from now on, but wonder how I can recreate that .. or get more insight into that ..
what you could do to help is open the console ( chrome dev tools ) , and just run that one test ..
then look at the network tab and see what json that mock ajax call is sending

I'd be super curious to see that result

@danielspaniel
Copy link
Collaborator

or .. maybe the mockjax request is not being used .. hmm .. that might be my first guess.
ooops . yes .. you have to put the handleFindAll before the visit .. yeah .. that was it ..
hooray .. I can put the liquor back on the shelves .. drink away test helpers, just come home before midnight!

@GCorbel
Copy link
Author

GCorbel commented Jul 27, 2015

I found a part of the solution, I have another test :

import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'social-learning/tests/helpers/start-app';
import TestHelper from 'ember-data-factory-guy/factory-guy-test-helper';
import FactoryGuy from 'ember-data-factory-guy';

var application;

module('Acceptance | show the list of skills', {
  beforeEach: function() {
    application = startApp();
  },

  afterEach: function() {
    Ember.run(application, 'destroy');
  }
});

test('Show the list of skills', function(assert) {
  var skills = FactoryGuy.makeList('skill', 1);
  TestHelper.handleFindQuery('skill', ['id'], skills);

  visit('/skills/1');

  andThen(function() {
    assert.equal(find('#skill #name').text(), skills[0].get('name'));
    assert.equal(currentURL(), '/skills/1');
  });
});

When I remove this test, the first one works. The api is triggered with this path /api/v1/skills/1 but not with /api/v1/skills/.

There is a weird behavior When I save the file, the api is called but when I rerun the test, it's not. The test is failing one time on two (for real). I think there is poltergeist in my acceptance test. I'm scared. Help me!

@danielspaniel
Copy link
Collaborator

Well @GCorbel, the poltergeist is always there when you forget to do 2 certain things. Look at my sample acceptance test and see if you can spot the things you are missing in setup and teardown.

@GCorbel
Copy link
Author

GCorbel commented Jul 28, 2015

You've exorcised. Thanks!

@GCorbel GCorbel closed this as completed Jul 28, 2015
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

3 participants