vendredi 21 août 2015

How to create then handle findAll with ember-data-factory-guy

I'm wondering if there is a way to create the following test with the awesome factory-guy ember addon.

test('can create new item', function(assert) {

  let newName = "New Item Name";

  Ember.run(function(){
    TestHelper.handleCreate('item').match({name:newName});

    // But somehow include the item that will be created from the previous call.
    TestHelper.handleFindAll('item', 5);

    // This page object visits fills in a field and submits.
    // It then redirects to items/index
    itemsNewPage
      .visit()
      .name(newName)
      .submit();

    andThen(function() {
      // Would like to be able to test for the existance of this item
      // with correct name
      assert.equal(itemsIndexPage.items(1).name(), newName, "item.name does not match new name");
    });
  });
});

This fails because the response from handleFind is not looking at what's in the store.

UPDATE Just as I finished writing this I realized my flaw. Here's what I'm doing now to solve this specific test, it doesn't do exactly what I was asking about above but thought I would add the solution:

Instead of:

TestHelper.handleFindAll('item', 5);

If we do this instead:

TestHelper.handleFindAll('item', 0);

That first item in the assertion will be the item just created but pulled from the store instead. Seems a little less brittle, being able to count on 1 being right. Would love some feedback on how to write a better test for something like this.

Thank you!




Aucun commentaire:

Enregistrer un commentaire