Ember 简单的 Auth 1.0 测试助手
Ember Simple Auth 1.0 Testing Helpers
我最近从 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"');
});
});
然后这些单独的测试通过了,但我似乎无法让它们用于实际用例。
如果能知道为什么会发生这种情况以及如何解决它,我们将不胜感激。
因此,为了防止其他人遇到这个问题,我设法通过在 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"');
});
});
我最近从 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"');
});
});
然后这些单独的测试通过了,但我似乎无法让它们用于实际用例。
如果能知道为什么会发生这种情况以及如何解决它,我们将不胜感激。
因此,为了防止其他人遇到这个问题,我设法通过在 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"');
});
});