Ember Simple Auth 1.0测试助手

时间:2023-01-30 01:19:00

I've recently upgraded from 0.8 to 1.0 and my app is working correctly.

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

One thing that surprised me though and I still don't understand is how the new acceptance test helpers should be used.

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

Previously (0.8) I could write my test like this and they would pass:

以前(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"');
  });
});

However, after upgrading and rewriting them in the new format:

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

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"');
  });
});

Only the first assertion now passes.

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

If I split them up into separate tests ie:

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

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"');
  });
});

Then these individual tests pass, but I cannot seem to get them working for actual use cases.

然后这些单独的测试通过,但我似乎无法使它们适用于实际用例。

Any ideas why this is happening and how to fix it would be very much appreciated.

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

1 个解决方案

#1


1  

So in case anyone else runs into this issue I managed to solve it by including the helpers in the andThen waiters, like this:

所以如果其他人遇到这个问题,我设法通过在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"');
  });
});

#1


1  

So in case anyone else runs into this issue I managed to solve it by including the helpers in the andThen waiters, like this:

所以如果其他人遇到这个问题,我设法通过在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"');
  });
});