test(frontend): upgrade mocha for promise support and fix async tests

This commit is contained in:
Zachary Carter 2014-03-19 11:05:00 -07:00
Родитель c215908589
Коммит ceef064a1e
15 изменённых файлов: 225 добавлений и 244 удалений

Просмотреть файл

@ -47,9 +47,19 @@ define([
}
}
function wrapAssertion(fn, done) {
try {
fn();
} catch (e) {
done(e);
}
done();
}
return {
requiresFocus: requiresFocus,
addFxaClientSpy: addFxaClientSpy,
removeFxaClientSpy: removeFxaClientSpy
removeFxaClientSpy: removeFxaClientSpy,
wrapAssertion: wrapAssertion
};
});

Просмотреть файл

@ -10,12 +10,14 @@ define([
'/tests/mocks/window.js',
'/tests/mocks/router.js',
'lib/session',
'lib/channels/fx-desktop'
'lib/channels/fx-desktop',
'/tests/lib/helpers.js'
],
function (chai, WindowMock, RouterMock, Session, FxDesktopChannel) {
function (chai, WindowMock, RouterMock, Session, FxDesktopChannel, TestHelpers) {
/*global describe, beforeEach, afterEach, it*/
var assert = chai.assert;
var channel;
var wrapAssertion = TestHelpers.wrapAssertion;
describe('lib/channel/fx-desktop', function () {
var windowMock;
@ -54,8 +56,9 @@ function (chai, WindowMock, RouterMock, Session, FxDesktopChannel) {
describe('init', function () {
it('sends the user to the settings page if signed in', function (done) {
channel.on('session_status', function () {
assert.equal(routerMock.page, 'settings');
done();
wrapAssertion(function () {
assert.equal(routerMock.page, 'settings');
}, done);
});
dispatchEvent('session_status', {
@ -65,8 +68,9 @@ function (chai, WindowMock, RouterMock, Session, FxDesktopChannel) {
it('sends the user to the signup page if not signed in', function (done) {
channel.on('session_status', function () {
assert.equal(routerMock.page, 'signup');
done();
wrapAssertion(function () {
assert.equal(routerMock.page, 'signup');
}, done);
});
// no data from session_status signifies no user is signed in.
@ -77,8 +81,9 @@ function (chai, WindowMock, RouterMock, Session, FxDesktopChannel) {
channel.window.location.pathname = '/signin';
channel.on('session_status', function () {
assert.notEqual(routerMock.page, 'signup');
done();
wrapAssertion(function () {
assert.notEqual(routerMock.page, 'signup');
}, done);
});
// no data from session_status signifies no user is signed in.
@ -95,8 +100,9 @@ function (chai, WindowMock, RouterMock, Session, FxDesktopChannel) {
it('retries sending until a response is received from the browser',
function (done) {
channel.send('wait-for-response', { key: 'value' }, function (err) {
assert.isNull(err);
done();
wrapAssertion(function () {
assert.isNull(err);
}, done);
});
setTimeout(function () {
@ -108,9 +114,9 @@ function (chai, WindowMock, RouterMock, Session, FxDesktopChannel) {
it('times out if browser does not respond', function (done) {
channel.send('wait-for-response', { key: 'value' }, function (err) {
assert.equal(String(err), 'Error: too many retries');
done();
wrapAssertion(function () {
assert.equal(String(err), 'Error: too many retries');
}, done);
});
});

Просмотреть файл

@ -29,7 +29,7 @@ function (chai, $, ChannelMock, testHelpers,
describe('lib/fxa-client', function () {
beforeEach(function (done) {
beforeEach(function () {
channelMock = new ChannelMock();
Session.clear();
Session.set('channel', channelMock);
@ -38,13 +38,12 @@ function (chai, $, ChannelMock, testHelpers,
client = new FxaClientWrapper({
language: 'it-CH'
});
client._getClientAsync()
return client._getClientAsync()
.then(function (_realClient) {
realClient = _realClient;
// create spies that can be used to check
// parameters that are passed to the FxaClient
testHelpers.addFxaClientSpy(realClient);
done();
});
});
@ -57,11 +56,11 @@ function (chai, $, ChannelMock, testHelpers,
});
describe('signUp/signUpResend', function () {
it('signUp signs up a user with email/password', function (done) {
it('signUp signs up a user with email/password', function () {
Session.set('service', 'sync');
Session.set('redirectTo', 'https://sync.firefox.com');
client.signUp(email, password)
return client.signUp(email, password)
.then(function () {
assert.equal(channelMock.message, 'login');
assert.isUndefined(channelMock.data.customizeSync);
@ -72,33 +71,21 @@ function (chai, $, ChannelMock, testHelpers,
redirectTo: 'https://sync.firefox.com',
lang: 'it-CH'
}));
done();
})
.then(null, function (err) {
assert.fail(err);
done();
});
});
it('informs browser of customizeSync option', function (done) {
client.signUp(email, password, { customizeSync: true })
it('informs browser of customizeSync option', function () {
return client.signUp(email, password, { customizeSync: true })
.then(function () {
assert.isTrue(channelMock.data.customizeSync);
done();
})
.then(null, function (err) {
assert.fail(err);
done();
});
});
it('signUpResend resends the validation email', function (done) {
it('signUpResend resends the validation email', function () {
Session.set('service', 'sync');
Session.set('redirectTo', 'https://sync.firefox.com');
client.signUp(email, password)
return client.signUp(email, password)
.then(function () {
return client.signUpResend();
})
@ -112,111 +99,82 @@ function (chai, $, ChannelMock, testHelpers,
lang: 'it-CH'
}
));
done();
})
.then(null, function (err) {
assert.fail(err);
done();
});
});
it('signUp existing user attempts to sign the user in', function (done) {
client.signUp(email, password)
it('signUp existing user attempts to sign the user in', function () {
return client.signUp(email, password)
.then(function () {
return client.signUp(email, password);
})
.then(function () {
assert.isTrue(realClient.signIn.called);
done();
})
.then(null, function (err) {
assert.fail(err);
done();
});
});
it('signUp existing verified user with incorrect password returns ' +
'incorrect password error', function (done) {
client.signUp(email, password, { preVerified: true })
'incorrect password error', function () {
return client.signUp(email, password, { preVerified: true })
.then(function () {
return client.signUp(email, 'incorrect');
})
.then(function () {
assert.fail('incorrect password should not lead to success');
done();
})
.then(null, function (err) {
throw new Error('incorrect password should not lead to success');
}, function (err) {
assert.isTrue(AuthErrors.is(err, 'INCORRECT_PASSWORD'));
done();
});
});
it('signUp existing unverified user with different password signs ' +
'user up again', function (done) {
client.signUp(email, password)
'user up again', function () {
return client.signUp(email, password)
.then(function () {
return client.signUp(email, 'different_password');
})
.then(function () {
assert.isTrue(realClient.signUp.called);
assert.isTrue(realClient.signIn.called);
done();
})
.then(null, function (err) {
assert.fail(err);
done();
});
});
});
describe('signIn', function () {
it('signin with unknown user should call errorback', function (done) {
client.signIn('unknown@unknown.com', 'password')
it('signin with unknown user should call errorback', function () {
return client.signIn('unknown@unknown.com', 'password')
.then(function (info) {
assert.fail('unknown user cannot sign in');
done();
}, function (err) {
assert.isTrue(true);
done();
});
});
it('signs a user in with email/password', function (done) {
client.signUp(email, password)
it('signs a user in with email/password', function () {
return client.signUp(email, password)
.then(function () {
return client.signIn(email, password);
})
.then(function () {
assert.equal(channelMock.message, 'login');
assert.isUndefined(channelMock.data.customizeSync);
done();
}, function (err) {
assert.fail(err);
done();
});
});
it('informs browser of customizeSync option', function (done) {
client.signUp(email, password)
it('informs browser of customizeSync option', function () {
return client.signUp(email, password)
.then(function () {
return client.signIn(email, password, true);
})
.then(function () {
assert.equal(channelMock.message, 'login');
assert.isTrue(channelMock.data.customizeSync);
done();
}, function (err) {
assert.fail(err);
done();
});
});
});
describe('passwordReset/passwordResetResend', function () {
it('requests a password reset', function (done) {
client.signUp(email, password)
it('requests a password reset', function () {
return client.signUp(email, password)
.then(function () {
Session.set('service', 'sync');
Session.set('redirectTo', 'https://sync.firefox.com');
@ -245,11 +203,6 @@ function (chai, $, ChannelMock, testHelpers,
lang: 'it-CH'
}
));
done();
})
.then(null, function (err) {
assert.fail(err);
done();
});
});
});
@ -258,61 +211,41 @@ function (chai, $, ChannelMock, testHelpers,
});
describe('signOut', function () {
it('signs the user out', function (done) {
client.signUp(email, password)
it('signs the user out', function () {
return client.signUp(email, password)
.then(function () {
return client.signOut();
})
.then(function () {
// positive test to ensure success case has an assertion
assert.isTrue(true);
done();
}, function (err) {
assert.fail(err);
done();
});
});
it('resolves to success on XHR failure', function (done) {
client.signUp(email, password)
it('resolves to success on XHR failure', function () {
return client.signUp(email, password)
.then(function () {
return client.signOut();
})
.then(function () {
// user has no session, this will cause an XHR error.
return client.signOut();
})
.then(function () {
// positive test to ensure success case has an assertion
assert.isTrue(true);
done();
}, function (err) {
assert.fail(err);
done();
});
});
});
describe('changePassword', function () {
it('changes the user\'s password', function (done) {
client.signUp(email, password, {preVerified: true})
it('changes the user\'s password', function () {
return client.signUp(email, password, {preVerified: true})
.then(function () {
return client.changePassword(email, password, 'new_password');
})
.then(function () {
// user is automatically re-authenticated with their new password
assert.equal(channelMock.message, 'login');
done();
}, function (err) {
assert.fail(err);
done();
});
});
});
describe('deleteAccount', function () {
it('deletes the user\'s account', function (done) {
client.signUp(email, password)
it('deletes the user\'s account', function () {
return client.signUp(email, password)
.then(function () {
return client.deleteAccount(email, password);
})
@ -320,19 +253,16 @@ function (chai, $, ChannelMock, testHelpers,
// this test is necessary because errors in deleteAccount
// should not be propagated to the final done's error
// handler
assert.fail('unexpected failure: ' + err.message);
done();
done(new Error('unexpected failure: ' + err.message));
})
.then(function () {
return client.signIn(email, password);
})
.then(function () {
assert.fail('should not be able to signin after account deletion');
done();
throw new Error('should not be able to signin after account deletion');
}, function () {
// positive test to ensure sign in failure case has an assertion
assert.isTrue(true);
done();
});
});
});

Просмотреть файл

@ -19,6 +19,7 @@ define([
function (chai, jQuery, BaseView, Translator, Template, DOMEventMock,
RouterMock, WindowMock, TestHelpers) {
var requiresFocus = TestHelpers.requiresFocus;
var wrapAssertion = TestHelpers.wrapAssertion;
/*global describe, beforeEach, afterEach, it*/
var assert = chai.assert;
@ -162,8 +163,9 @@ function (chai, jQuery, BaseView, Translator, Template, DOMEventMock,
describe('navigate', function () {
it('navigates to a page', function (done) {
router.on('navigate', function (newPage) {
assert.equal(newPage, 'signin');
done();
wrapAssertion(function() {
assert.equal(newPage, 'signin');
}, done);
});
view.navigate('signin');
});
@ -205,8 +207,9 @@ function (chai, jQuery, BaseView, Translator, Template, DOMEventMock,
describe('BaseView.preventDefaultThen', function () {
it('can take the name of a function as the name of the event handler', function (done) {
view.eventHandler = function (event) {
assert.isTrue(event.isDefaultPrevented());
done();
wrapAssertion(function() {
assert.isTrue(event.isDefaultPrevented());
}, done);
};
var backboneHandler = BaseView.preventDefaultThen('eventHandler');
@ -215,8 +218,9 @@ function (chai, jQuery, BaseView, Translator, Template, DOMEventMock,
it('can take a function as the event handler', function (done) {
function eventHandler(event) {
assert.isTrue(event.isDefaultPrevented());
done();
wrapAssertion(function() {
assert.isTrue(event.isDefaultPrevented());
}, done);
}
var backboneHandler = BaseView.preventDefaultThen(eventHandler);

Просмотреть файл

@ -12,10 +12,12 @@ define([
'views/change_password',
'lib/fxa-client',
'lib/session',
'../../mocks/router'
'../../mocks/router',
'../../lib/helpers'
],
function (chai, _, $, View, FxaClient, Session, RouterMock) {
function (chai, _, $, View, FxaClient, Session, RouterMock, TestHelpers) {
var assert = chai.assert;
var wrapAssertion = TestHelpers.wrapAssertion;
describe('views/change_password', function () {
var view, router, email;
@ -38,8 +40,9 @@ function (chai, _, $, View, FxaClient, Session, RouterMock) {
describe('with no session', function () {
it('redirects to signin', function (done) {
router.on('navigate', function (newPage) {
assert.equal(newPage, 'signin');
done();
wrapAssertion(function () {
assert.equal(newPage, 'signin');
}, done);
});
var isRendered = view.render();
@ -97,8 +100,9 @@ function (chai, _, $, View, FxaClient, Session, RouterMock) {
view.$('#new_password').val('password');
view.on('validation_error', function(which, msg) {
assert.ok(msg);
done();
wrapAssertion(function () {
assert.ok(msg);
}, done);
});
view.showValidationErrors();
@ -109,8 +113,9 @@ function (chai, _, $, View, FxaClient, Session, RouterMock) {
view.$('#new_password').val('passwor');
view.on('validation_error', function(which, msg) {
assert.ok(msg);
done();
wrapAssertion(function () {
assert.ok(msg);
}, done);
});
view.showValidationErrors();
@ -123,8 +128,9 @@ function (chai, _, $, View, FxaClient, Session, RouterMock) {
$('#new_password').val('password');
view.on('error', function (msg) {
assert.ok(msg);
done();
wrapAssertion(function () {
assert.ok(msg);
}, done);
});
view.submit();

Просмотреть файл

@ -8,10 +8,12 @@
define([
'chai',
'views/complete_reset_password',
'../../mocks/window'
'../../mocks/window',
'../../lib/helpers'
],
function (chai, View, WindowMock) {
function (chai, View, WindowMock, TestHelpers) {
var assert = chai.assert;
var wrapAssertion = TestHelpers.wrapAssertion;
describe('views/complete_reset_password', function () {
var view, windowMock;
@ -137,8 +139,9 @@ function (chai, View, WindowMock) {
view.$('#vpassword').val('password');
view.on('validation_error', function(which, msg) {
assert.ok(msg);
done();
wrapAssertion(function() {
assert.ok(msg);
}, done);
});
view.showValidationErrors();
@ -149,8 +152,9 @@ function (chai, View, WindowMock) {
view.$('#vpassword').val('passwor');
view.on('validation_error', function(which, msg) {
assert.ok(msg);
done();
wrapAssertion(function() {
assert.ok(msg);
}, done);
});
view.showValidationErrors();

Просмотреть файл

@ -14,14 +14,15 @@ define([
'../../lib/helpers'
],
function (chai, View, Session, FxaClientWrapper,
WindowMock, testHelpers) {
WindowMock, TestHelpers) {
/*global describe, beforeEach, afterEach, it*/
var assert = chai.assert;
var wrapAssertion = TestHelpers.wrapAssertion;
describe('views/complete_sign_up', function () {
var view, windowMock, client;
beforeEach(function (done) {
beforeEach(function () {
Session.clear();
windowMock = new WindowMock();
@ -30,13 +31,12 @@ function (chai, View, Session, FxaClientWrapper,
});
$('#container').html(view.el);
var clientWrapper = new FxaClientWrapper();
clientWrapper._getClientAsync()
return clientWrapper._getClientAsync()
.then(function (_client) {
client = _client;
// create spies that can be used to check
// parameters that are passed to the Fxaclient
testHelpers.addFxaClientSpy(client);
done();
TestHelpers.addFxaClientSpy(client);
});
});
@ -48,7 +48,7 @@ function (chai, View, Session, FxaClientWrapper,
view = windowMock = null;
// return the client to its original state.
testHelpers.removeFxaClientSpy(client);
TestHelpers.removeFxaClientSpy(client);
});
describe('constructor creates it', function () {
@ -64,10 +64,10 @@ function (chai, View, Session, FxaClientWrapper,
windowMock.location.search = '?code=code';
view.on('error', function (msg) {
assert.ok(msg);
assert.isFalse(client.verifyCode.called);
done();
wrapAssertion(function() {
assert.ok(msg);
assert.isFalse(client.verifyCode.called);
}, done);
});
view.render();
});
@ -76,10 +76,10 @@ function (chai, View, Session, FxaClientWrapper,
windowMock.location.search = '?uid=uid';
view.on('error', function (msg) {
assert.ok(msg);
assert.isFalse(client.verifyCode.called);
done();
wrapAssertion(function() {
assert.ok(msg);
assert.isFalse(client.verifyCode.called);
}, done);
});
view.render();
});
@ -88,8 +88,9 @@ function (chai, View, Session, FxaClientWrapper,
windowMock.location.search = '?code=code&uid=uid';
view.on('verify_code_complete', function () {
assert.isTrue(client.verifyCode.called);
done();
wrapAssertion(function() {
assert.isTrue(client.verifyCode.called);
}, done);
});
view.render();

Просмотреть файл

@ -52,26 +52,23 @@ function (chai, View, FxaClient, RouterMock) {
});
it('resend only occurs when clicking on #resend', function (done) {
it('resend only occurs when clicking on #resend', function () {
var client = new FxaClient();
var email = 'user' + Math.random() + '@testuser.com';
client.signUp(email, 'password')
.then(function () {
return client.signUp(email, 'password')
.then(function () {
var count = 0;
view.on('resending', function () {
count++;
});
view.$('section').click();
assert.equal(count, 0);
view.$('#resend').click();
assert.equal(count, 1);
done();
});
});
});
});

Просмотреть файл

@ -55,26 +55,23 @@ function (chai, View, FxaClient, RouterMock) {
});
it('resend only occurs when clicking on #resend', function (done) {
it('resend only occurs when clicking on #resend', function () {
var client = new FxaClient();
var email = 'user' + Math.random() + '@testuser.com';
client.signUp(email, 'password')
.then(function () {
return client.signUp(email, 'password')
.then(function () {
var count = 0;
view.on('resending', function () {
count++;
});
view.$('section').click();
assert.equal(count, 0);
view.$('#resend').click();
assert.equal(count, 1);
done();
});
});
});
});

Просмотреть файл

@ -11,11 +11,13 @@ define([
'views/delete_account',
'lib/fxa-client',
'lib/session',
'../../mocks/router'
'../../mocks/router',
'../../lib/helpers'
],
function (chai, $, View, FxaClient, Session, RouterMock) {
function (chai, $, View, FxaClient, Session, RouterMock, TestHelpers) {
/*global describe, beforeEach, afterEach, it*/
var assert = chai.assert;
var wrapAssertion = TestHelpers.wrapAssertion;
describe('views/delete_account', function () {
var view, router, email, password = 'password';
@ -38,8 +40,9 @@ function (chai, $, View, FxaClient, Session, RouterMock) {
describe('with no session', function () {
it('redirects to signin', function (done) {
router.on('navigate', function (newPage) {
assert.equal(newPage, 'signin');
done();
wrapAssertion(function() {
assert.equal(newPage, 'signin');
}, done);
});
var isRendered = view.render();
@ -48,16 +51,15 @@ function (chai, $, View, FxaClient, Session, RouterMock) {
});
describe('with session', function () {
beforeEach(function (done) {
beforeEach(function () {
email = 'testuser.' + Math.random() + '@testuser.com';
var client = new FxaClient();
client.signUp(email, 'password')
return client.signUp(email, 'password')
.then(function () {
view.render();
$('body').append(view.el);
done();
});
});
@ -85,8 +87,9 @@ function (chai, $, View, FxaClient, Session, RouterMock) {
view.$('[type=password]').val('passwor');
view.on('validation_error', function(which, msg) {
assert.ok(msg);
done();
wrapAssertion(function() {
assert.ok(msg);
}, done);
});
view.showValidationErrors();
@ -99,8 +102,9 @@ function (chai, $, View, FxaClient, Session, RouterMock) {
$('form input[type=password]').val(password);
router.on('navigate', function (newPage) {
assert.equal(newPage, 'signup');
done();
wrapAssertion(function() {
assert.equal(newPage, 'signup');
}, done);
});
view.submit();

Просмотреть файл

@ -10,11 +10,13 @@ define([
'views/reset_password',
'lib/fxa-client',
'../../mocks/window',
'../../mocks/router'
'../../mocks/router',
'../../lib/helpers'
],
function (chai, View, FxaClient, WindowMock, RouterMock) {
function (chai, View, FxaClient, WindowMock, RouterMock, TestHelpers) {
/*global describe, beforeEach, afterEach, it*/
var assert = chai.assert;
var wrapAssertion = TestHelpers.wrapAssertion;
describe('views/reset_password', function () {
var view, router;
@ -64,8 +66,9 @@ function (chai, View, FxaClient, WindowMock, RouterMock) {
view.$('[type=email]').val('testuser');
view.on('validation_error', function (which, msg) {
assert.ok(msg);
done();
wrapAssertion(function() {
assert.ok(msg);
}, done);
});
view.showValidationErrors();
@ -81,8 +84,9 @@ function (chai, View, FxaClient, WindowMock, RouterMock) {
view.$('input[type=email]').val(email);
router.on('navigate', function () {
assert.equal(router.page, 'confirm_reset_password');
done();
wrapAssertion(function() {
assert.equal(router.page, 'confirm_reset_password');
}, done);
});
view.submit();

Просмотреть файл

@ -12,10 +12,12 @@ define([
'views/settings',
'lib/fxa-client',
'lib/session',
'../../mocks/router'
'../../mocks/router',
'../../lib/helpers'
],
function (chai, _, $, View, FxaClient, Session, RouterMock) {
function (chai, _, $, View, FxaClient, Session, RouterMock, TestHelpers) {
var assert = chai.assert;
var wrapAssertion = TestHelpers.wrapAssertion;
describe('views/settings', function () {
var view, router, email;
@ -38,8 +40,9 @@ function (chai, _, $, View, FxaClient, Session, RouterMock) {
describe('with no session', function () {
it('redirects to signin', function(done) {
router.on('navigate', function (newPage) {
assert.equal(newPage, 'signin');
done();
wrapAssertion(function() {
assert.equal(newPage, 'signin');
}, done);
});
var isRendered = view.render();
@ -48,24 +51,24 @@ function (chai, _, $, View, FxaClient, Session, RouterMock) {
});
describe('with session', function () {
beforeEach(function (done) {
beforeEach(function () {
email = 'testuser.' + Math.random() + '@testuser.com';
var client = new FxaClient();
client.signUp(email, 'password')
return client.signUp(email, 'password')
.then(function() {
view.render();
$('body').append(view.el);
done();
});
});
describe('signOut', function () {
it('signs the user out, redirects to signin page', function (done) {
router.on('navigate', function (newPage) {
assert.equal(newPage, 'signin');
done();
wrapAssertion(function() {
assert.equal(newPage, 'signin');
}, done);
});
view.signOut();

Просмотреть файл

@ -16,9 +16,10 @@ define([
'../../lib/helpers'
],
function (chai, $, View, Session, FxaClient,
WindowMock, RouterMock, testHelpers) {
WindowMock, RouterMock, TestHelpers) {
/*global describe, beforeEach, afterEach, it*/
var assert = chai.assert;
var wrapAssertion = TestHelpers.wrapAssertion;
describe('views/sign_in', function () {
var view, email, router;
@ -93,14 +94,14 @@ function (chai, $, View, Session, FxaClient,
$('[type=password]').val(password);
router.on('navigate', function () {
assert.equal(router.page, 'confirm');
done();
wrapAssertion(function () {
assert.equal(router.page, 'confirm');
}, done);
});
view.submit();
})
.then(null, function (err) {
assert.fail(String(err));
done();
done(new Error(err));
});
});
@ -112,8 +113,9 @@ function (chai, $, View, Session, FxaClient,
$('[type=password]').val('incorrect');
view.on('error', function (msg) {
assert.ok(msg.indexOf('Incorrect') > -1);
done();
wrapAssertion(function () {
assert.ok(msg.indexOf('Incorrect') > -1);
}, done);
});
view.submit();
});
@ -124,8 +126,9 @@ function (chai, $, View, Session, FxaClient,
$('[type=password]').val('incorrect');
view.on('error', function (msg) {
assert.ok(msg.indexOf('/signup') > -1);
done();
wrapAssertion(function () {
assert.ok(msg.indexOf('/signup') > -1);
}, done);
});
view.submit();
});
@ -137,8 +140,9 @@ function (chai, $, View, Session, FxaClient,
view.$('[type=password]').val('password');
view.on('validation_error', function (which, msg) {
assert.ok(msg);
done();
wrapAssertion(function () {
assert.ok(msg);
}, done);
});
view.showValidationErrors();
@ -149,8 +153,9 @@ function (chai, $, View, Session, FxaClient,
view.$('[type=password]').val('passwor');
view.on('validation_error', function (which, msg) {
assert.ok(msg);
done();
wrapAssertion(function () {
assert.ok(msg);
}, done);
});
view.showValidationErrors();
@ -160,21 +165,20 @@ function (chai, $, View, Session, FxaClient,
describe('resetPasswordNow', function () {
var client;
beforeEach(function (done) {
beforeEach(function () {
var clientWrapper = new FxaClient();
clientWrapper._getClientAsync()
return clientWrapper._getClientAsync()
.then(function (_client) {
client = _client;
// create spies that can be used to check
// parameters that are passed to the Fxaclient
testHelpers.addFxaClientSpy(client);
done();
TestHelpers.addFxaClientSpy(client);
});
});
afterEach(function () {
// return the client to its original state.
testHelpers.removeFxaClientSpy(client);
TestHelpers.removeFxaClientSpy(client);
});
it('only works from /force_auth', function () {
@ -264,19 +268,18 @@ function (chai, $, View, Session, FxaClient,
Session.set('forceAuth', true);
Session.set('forceEmail', email);
router.on('navigate', function () {
assert.equal(router.page, 'confirm_reset_password');
wrapAssertion(function () {
assert.equal(router.page, 'confirm_reset_password');
assert.isTrue(event.isDefaultPrevented());
assert.isTrue(event.isPropagationStopped());
done();
assert.isTrue(event.isDefaultPrevented());
assert.isTrue(event.isPropagationStopped());
}, done);
});
view.resetPasswordNow(event);
})
.then(null, function (err) {
assert.fail(String(err));
done();
done(new Error(err));
});
});
});

Просмотреть файл

@ -12,11 +12,13 @@ define([
'views/sign_up',
'lib/session',
'lib/fxa-client',
'../../mocks/router'
'../../mocks/router',
'../../lib/helpers'
],
function (chai, _, $, View, Session, FxaClient, RouterMock) {
function (chai, _, $, View, Session, FxaClient, RouterMock, TestHelpers) {
/*global describe, beforeEach, afterEach, it*/
var assert = chai.assert;
var wrapAssertion = TestHelpers.wrapAssertion;
describe('views/sign_up', function () {
var view, router, email;
@ -232,8 +234,9 @@ function (chai, _, $, View, Session, FxaClient, RouterMock) {
view.$('#fxa-age-year').val('1990');
view.on('validation_error', function(which, msg) {
assert.ok(msg);
done();
wrapAssertion(function () {
assert.ok(msg);
}, done);
});
view.showValidationErrors();
@ -245,8 +248,9 @@ function (chai, _, $, View, Session, FxaClient, RouterMock) {
view.$('#fxa-age-year').val('1990');
view.on('validation_error', function(which, msg) {
assert.ok(msg);
done();
wrapAssertion(function () {
assert.ok(msg);
}, done);
});
view.showValidationErrors();
@ -257,8 +261,9 @@ function (chai, _, $, View, Session, FxaClient, RouterMock) {
view.$('[type=password]').val('passwor');
view.on('validation_error', function(which, msg) {
assert.ok(msg);
done();
wrapAssertion(function () {
assert.ok(msg);
}, done);
});
view.showValidationErrors();
@ -274,8 +279,9 @@ function (chai, _, $, View, Session, FxaClient, RouterMock) {
$('#fxa-age-year').val(nowYear - 14);
router.on('navigate', function () {
assert.equal(router.page, 'confirm');
done();
wrapAssertion(function () {
assert.equal(router.page, 'confirm');
}, done);
});
view.submit();
});
@ -288,8 +294,9 @@ function (chai, _, $, View, Session, FxaClient, RouterMock) {
$('#fxa-age-year').val(nowYear - 14);
router.on('navigate', function () {
assert.equal(router.page, 'confirm');
done();
wrapAssertion(function () {
assert.equal(router.page, 'confirm');
}, done);
});
// submit using the enter key
@ -305,8 +312,9 @@ function (chai, _, $, View, Session, FxaClient, RouterMock) {
$('#fxa-age-year').val(nowYear - 13);
router.on('navigate', function () {
assert.equal(router.page, 'cannot_create_account');
done();
wrapAssertion(function () {
assert.equal(router.page, 'cannot_create_account');
}, done);
});
view.submit();
});
@ -325,8 +333,9 @@ function (chai, _, $, View, Session, FxaClient, RouterMock) {
var revisitRouter = new RouterMock();
revisitRouter.on('navigate', function () {
assert.equal(revisitRouter.page, 'cannot_create_account');
done();
wrapAssertion(function () {
assert.equal(revisitRouter.page, 'cannot_create_account');
}, done);
});
var revisitView = new View({
@ -347,8 +356,9 @@ function (chai, _, $, View, Session, FxaClient, RouterMock) {
$('#fxa-age-year').val(nowYear - 14);
router.on('navigate', function () {
assert.equal(router.page, 'confirm');
done();
wrapAssertion(function () {
assert.equal(router.page, 'confirm');
}, done);
});
view.submit();
});
@ -365,8 +375,9 @@ function (chai, _, $, View, Session, FxaClient, RouterMock) {
$('#fxa-age-year').val(nowYear - 14);
view.on('error', function (msg) {
assert.ok(msg.indexOf('/signin') > -1);
done();
wrapAssertion(function () {
assert.ok(msg.indexOf('/signin') > -1);
}, done);
});
view.submit();
});
@ -383,8 +394,9 @@ function (chai, _, $, View, Session, FxaClient, RouterMock) {
$('#fxa-age-year').val(nowYear - 14);
router.on('navigate', function () {
assert.equal(router.page, 'confirm');
done();
wrapAssertion(function () {
assert.equal(router.page, 'confirm');
}, done);
});
view.submit();
});

Просмотреть файл

@ -13,7 +13,7 @@
"requirejs-mustache": "https://github.com/jfparadis/requirejs-mustache.git#5fb8c0a3e8560526e8f9617a689e2924a8532d0a",
"mustache": "0.7.3",
"requirejs-text": "2.0.10",
"mocha": "1.16.2",
"mocha": "1.18.2",
"chai": "1.8.1",
"p": "https://github.com/rkatic/p.git#c6a451ef6080f10f9c31489c127ca3b291d0bc5a",
"sinon": "http://sinonjs.org/releases/sinon-1.7.1.js",