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

Confusing behavior with handleQuery related to setup and teardown in acceptance test #164

Closed
Andrew-Max opened this issue Dec 21, 2015 · 5 comments

Comments

@Andrew-Max
Copy link

here is my setup block:

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

var App;
var hardware;

module('Acceptance | UI | Hardware Status', {
  beforeEach: function() {
    App = startApp();
    TestHelper.setup();
    authenticateSession();
    setup(true, true);
    Ember.run(function () {
      hardware = FactoryGuy.makeList('hardware', 2, {type: "quad"});
      TestHelper.handleCreate('hardware');
      TestHelper.handleQuery('hardware', {"type": "quad"}, hardware);
    })
  },

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

Afterwards a handle query in the first test that runs will always fail and throw and adaptor error:

test('hardware status route index', function(assert) {
  assert.expect(5);
  visit('admin/hardware-status/');

  andThen(function() {
    assert.equal(currentPath(), 'admin.hardware-status.index');
    //GET http://localhost:1337/v1/hardware?type=quad 403 (Forbidden)
   // Error while processing route: admin.hardware-status.index Adapter operation failed Error: Adapter operation failed
    // handleQuery does not seem to be handling the query thus breaking the test
  });
});

but bizarrely if I run the same test n times in succession all but the first will pass

test('hardware status route index', function(assert) {
  visit('admin/hardware-status/');

  andThen(function() {
    assert.equal(currentPath(), 'admin.hardware-status.index');   
    //GET http://localhost:1337/v1/hardware?type=quad 403 (Forbidden)
    // Error while processing route: admin.hardware-status.index Adapter operation failed Error: Adapter operation failed
    // handleQuery does not seem to be handling the query thus breaking the test
  });

test('hardware status route index 2', function(assert) {
  assert.expect(5);
  visit('admin/hardware-status/');

  andThen(function() {
    assert.equal(currentPath(), 'admin.hardware-status.index');
    //No GET, Query handled, everything works, test passes
  });
});

adding an empty test visists the route and makes no assertions fixes it but obviously that isnt desirable. Any thoughts on why handleQuery seems to noop on the first run through?

@danielspaniel
Copy link
Collaborator

If you are using the latest factory guy .. ( 2.1.2 or 2.1.3 ) you have to do this:

TestHelper.handleQuery('hardware', {"type": "quad"}).returnsModels([hardware]);

instead of this:

TestHelper.handleQuery('hardware', {"type": "quad"}, hardware);

Give that a try and let me know what happens

@Andrew-Max
Copy link
Author

ahhh. Will try and report back. Thanks as usual!

@Andrew-Max
Copy link
Author

hmmm actually still on 2.0.3. Let me try to get my other tests working and then I'll update and see if it fixes it.

@danielspaniel
Copy link
Collaborator

any progress?

@danielspaniel
Copy link
Collaborator

last call .. before I close this?

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