0

我最近从 0.8 升级到 1.0,我的应用程序运行正常。

让我感到惊讶但我仍然不明白的一件事是应该如何使用新的验收测试助手。

以前(0.8)我可以这样写我的测试,他们会通过:

test('sign in and sign out', function(assert) {
  visit('/');

  andThen(function() {
    assert.ok(find(':contains("Sign In")').length,
      'expected to see "Sign In"');
  });

  authenticateSession();

  andThen(function() {
    assert.ok(find(':contains("Sign Out")').length,
      'expected to see "Sign Out"');
  });

  invalidateSession();

  andThen(function() {
    assert.ok(find(':contains("Sign In")').length,
      'expected to see "Sign In"');
  });
});

但是,在以新格式升级和重写它们之后:

import { authenticateSession, invalidateSession } from 'instatube-app/tests/helpers/ember-simple-auth';

test('sign in and sign out', function(assert) {
  visit('/');

  andThen(function() {
    assert.ok(find(':contains("Sign In")').length,
      'expected to see "Sign In"');
  });

  authenticateSession(application);

  andThen(function() {
    assert.ok(find(':contains("Sign Out")').length,
      'expected to see "Sign Out"');
  });

  invalidateSession(application);

  andThen(function() {
    assert.ok(find(':contains("Sign In")').length,
      'expected to see "Sign In"');
  });
});

现在只有第一个断言通过。

如果我将它们分成单独的测试,即:

test('when signed out display sign in button', function(assert) {
  visit('/');

  andThen(function() {
    assert.ok(find(':contains("Sign In")').length,
      'expected to see "Sign In"');
  });

});

test('when signed in display sign out button', function(assert) {
  authenticateSession(application);
  visit('/');

  andThen(function() {
    assert.ok(find(':contains("Sign Out")').length,
      'expected to see "Sign Out"');
  });
});

然后这些单独的测试通过了,但我似乎无法让它们在实际用例中工作。

任何想法为什么会发生这种情况以及如何解决它将不胜感激。

4

1 回答 1

1

因此,如果其他人遇到这个问题,我设法通过在 andThen 服务员中包含助手来解决它,如下所示:

import { authenticateSession, invalidateSession } from 'instatube-app/tests/helpers/ember-simple-auth';

test('sign in and sign out', function(assert) {
  visit('/');

  andThen(function() {
    assert.ok(find(':contains("Sign In")').length,
      'expected to see "Sign In"');
    authenticateSession(application);
  });

  andThen(function() {
    assert.ok(find(':contains("Sign Out")').length,
      'expected to see "Sign Out"');
    invalidateSession(application);
  });

  andThen(function() {
    assert.ok(find(':contains("Sign In")').length,
      'expected to see "Sign In"');
  });
});
于 2016-03-18T10:16:35.080 回答