Async Jasmine test of user roles times out

I posted this over on Stack, but I haven’t gotten any help yet. Thought I would bring it up to you fine folks.

That’s the stack post if you want to look at it there. Here’s the gist of it. I’ve written some Jasmine client integration tests to check that my user permissions are working properly. Both “Users with manage-users role” and “Users with manage-users role” timeout.

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

Chrome also complains that newUser is undefined.

Exception from Tracker afterFlush function: Cannot read property ‘_id’ of undefined

Here are the tests I’m trying to run:

describe('Users', function() {
    it('should be able to log in', function(done) {
        expect(Meteor.userId()).toBeNull();

        Meteor.loginWithPassword('mgoldsborough@gmail.com', '12345678', function(error) {
            expect(error).toBeUndefined();
            expect(Meteor.userId()).not.toBeNull();

            Meteor.logout(function() {
                done();
            });
        });
    });
});

describe('Users with manage-users role', function() {

    beforeEach(function(done) {
        Meteor.loginWithPassword('mgoldsborough@gmail.com', '12345678', function(error) {
            console.log('Logged in as admin');
            done();
        });
    });

    afterEach(function(done) {
        Meteor.logout(function() {
            console.log('Logged out');
            done();
        });
    });

    it('should be able to change users roles', function(done) {
        Router.go('users');
        Tracker.afterFlush(function() {
            var newUser = Meteor.users.findOne({email: 'devon@radworks.io'});
            console.log('New user id: ' + newUser._id);
            $('#user-' + newUser._id + '-roles').val('manage-users');
            expect(Roles.userIsInRole(newUser, 'manage-users')).toBe(true);
            expect(Roles.userIsInRole(newUser, 'edit-any')).toBe(false);
            done();
        });
    });
});

describe('Users without manage-user role', function() {

    beforeEach(function(done) {
        Meteor.loginWithPassword('mgoldsborough@gmail.com', '12345678', function(error) {
            console.log('Logged in as admin');
            done();
        });
    });

    afterEach(function(done) {
        Meteor.logout(function() {
            console.log('Logged out');
            done();
        });
    });

    it('should not be able to change user roles', function(done) {
        Router.go('users');
        Tracker.afterFlush(function() {
            var newUser = Meteor.users.findOne({email: 'devon@radworks.io'});
            console.log('New user id for w/o manage-user test: ' + newUser._id);
            $('#user-' + newUser._id + '-roles').val('manage-users');
            expect(Roles.userIsInRole(newUser, 'manage-users')).toBe(false);
            done();
        });
    });
});

I don’t understand why I have a timeout or why newUser is not defined. That user is being created in my fixtures in the same way as the user I’m logging in as, and those seem to work fine. I’ve written a server integration test that uses this user without issue.

describe('New users after the first', function() {
    var newUser;

    beforeAll(function() {
        newUser = Meteor.users.find({email: 'devon@radworks.io'});
    });

    it('do not have the manage-users role', function() {
        expect(Roles.userIsInRole(newUser, 'manage-users')).toBe(false);
    });
    it('do not have the schedule-any role', function() {
        expect(Roles.userIsInRole(newUser, 'schedule-any')).toBe(false);
    });
    it('do not have the edit-any role', function() {
        expect(Roles.userIsInRole(newUser, 'edit-any')).toBe(false);
    });
});

Can anyone point me in the right direction?