Move stub setup outside the test method
Stubs should be restored outside the test method in which they are used to ensure that they are properly restored no matter the result of the test (for example, if an exception is thrown). Besides that, this will make possible to reuse the stub in other sibling tests without having to explicitly setup it in them. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
d606219576
commit
fcef15af80
|
@ -30,7 +30,6 @@ describe('OC.Share.ShareDialogView', function() {
|
||||||
var saveLinkShareStub;
|
var saveLinkShareStub;
|
||||||
|
|
||||||
var fetchStub;
|
var fetchStub;
|
||||||
var notificationStub;
|
|
||||||
|
|
||||||
var configModel;
|
var configModel;
|
||||||
var shareModel;
|
var shareModel;
|
||||||
|
@ -473,6 +472,16 @@ describe('OC.Share.ShareDialogView', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('autocompletion of users', function() {
|
describe('autocompletion of users', function() {
|
||||||
|
var showNotificationStub;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
showNotificationStub = sinon.stub(OC.Notification, 'show');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
showNotificationStub.restore();
|
||||||
|
});
|
||||||
|
|
||||||
describe('triggers autocomplete display and focus with data when ajax search succeeds', function () {
|
describe('triggers autocomplete display and focus with data when ajax search succeeds', function () {
|
||||||
it('users', function () {
|
it('users', function () {
|
||||||
dialog.render();
|
dialog.render();
|
||||||
|
@ -1474,12 +1483,10 @@ describe('OC.Share.ShareDialogView', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws a notification when the ajax search lookup fails', function () {
|
it('throws a notification when the ajax search lookup fails', function () {
|
||||||
notificationStub = sinon.stub(OC.Notification, 'show');
|
|
||||||
dialog.render();
|
dialog.render();
|
||||||
dialog.autocompleteHandler({term: 'bob'}, sinon.stub());
|
dialog.autocompleteHandler({term: 'bob'}, sinon.stub());
|
||||||
fakeServer.requests[0].respond(500);
|
fakeServer.requests[0].respond(500);
|
||||||
expect(notificationStub.calledOnce).toEqual(true);
|
expect(showNotificationStub.calledOnce).toEqual(true);
|
||||||
notificationStub.restore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('renders the autocomplete elements', function() {
|
describe('renders the autocomplete elements', function() {
|
||||||
|
|
Loading…
Reference in New Issue