I am writing my first ever ember tests. I am using ember-cli and ember 1.13.6 with simple-auth 0.8.0
I am seeing some baffling behavior while running my tests in headless mode with phantom.js
The odd behavior seems to occur when I chain multiple andThen()
statements. In my app, if a user is not authenticated, all route transitions should redirect to /login
. Right now this happens during the first andThen()
of a given test but any transitions in a following andThen()
will allow unauthenticated users through to a restricted route
eg:
test('unauthenticated', function(assert) {
assert.expect(1);
visit('/maps');
andThen(function() {
assert.equal(currentURL(), '/login', "viewing authenticated routes while unauthenticated redirects to login");
//this test passes
});
visit('/maps');
andThen(function() {
assert.equal(currentURL(), '/login', "viewing authenticated routes while unauthenticated redirects to login");
//this test fails
});
});
Although the app does seem to be somewhat aware of simple auth because this all passes:
test('unauthenticated', function(assert) {
assert.expect(1);
visit('/maps');
andThen(function() {
assert.equal(currentURL(), '/login', "viewing authenticated routes while unauthenticated redirects to login");
});
});
test('authenticated', function(assert) {
assert.expect(1);
authenticateSession();
visit('/maps');
andThen(function() {
assert.equal(currentURL(), '/maps', "able to view authenticated route after authenticating");
});
});
A final weird behavior I'm seeing is that authenticateSession() works when called before the first andThen
as in the previous example but fails with the error ReferenceError: Can't find variable: Promise
if called after the first andThen()
like:
test('unauthenticated', function(assert) {
assert.expect(1);
visit('/maps');
andThen(function() {
assert.equal(currentURL(), '/login', "viewing authenticated routes while unauthenticated redirects to login");
});
authenticateSession();
});
Aucun commentaire:
Enregistrer un commentaire