vendredi 23 septembre 2016

Nesting ember acceptance test helpers in "andThen"

I've always written ember tests like this:

test('should add new post', function(assert) {
  visit('/posts/new');

  fillIn('input.title', 'My new post');
  click('button.submit');

  andThen(() => {
    assert.equal(find('ul.posts li:first').text(), 'My new post')
  });

  click('button.edit');
  fillIn('input.title', 'My edited post');
  click('button.submit');

  andThen(() => {
    assert.equal(find('ul.posts li:first').text(), 'My edited post')
  });
});

but I also see tests written "nested" style like this:

test('should add new post', function(assert) {
  visit('/posts/new');

  fillIn('input.title', 'My new post');
  click('button.submit');

  andThen(() => {
    assert.equal(find('ul.posts li:first').text(), 'My new post')

    click('button.edit');
    fillIn('input.title', 'My edited post');
    click('button.submit');

    andThen(() => {
      assert.equal(find('ul.posts li:first').text(), 'My edited post')
    });
  });
});

Is one way better than the other or correct? Could the first style be a source of race conditions?




Aucun commentaire:

Enregistrer un commentaire