From bafcfba65ff92193a41f83fe2e2fd45a5a5d817c Mon Sep 17 00:00:00 2001 From: Zak Henry Date: Wed, 15 Jul 2015 12:37:38 +1000 Subject: [PATCH] Refactored sinon spy definitions out of the test blocks --- app/src/app/guest/login/login.spec.ts | 55 ++++++++++++++++++--------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/app/src/app/guest/login/login.spec.ts b/app/src/app/guest/login/login.spec.ts index 06a8c951..48db1f9e 100644 --- a/app/src/app/guest/login/login.spec.ts +++ b/app/src/app/guest/login/login.spec.ts @@ -35,42 +35,61 @@ describe('Login', () => { }); - it('should resolve the dialog when login credentials are passed', () => { + describe('dialog interactions', () => { - sinon.spy($mdDialog, 'hide'); + beforeEach(() => { - let creds = { - username: 'foo', - password: 'bar', - }; + sinon.spy($mdDialog, 'hide'); + sinon.spy($mdDialog, 'cancel'); + sinon.spy($mdDialog, 'show'); - ($scope).login(creds.username, creds.password); + }); - expect($mdDialog.hide).to.have.been.calledWith(creds); + afterEach(() => { - }); + ($mdDialog).hide.restore(); + ($mdDialog).cancel.restore(); + ($mdDialog).show.restore(); - it('should cancel dialog when requested', () => { + }); - sinon.spy($mdDialog, 'cancel'); + it('should resolve the dialog when login credentials are passed', () => { - ($scope).cancelLoginDialog(); - expect($mdDialog.cancel).to.have.been.called; + let creds = { + username: 'foo', + password: 'bar', + }; + + ($scope).login(creds.username, creds.password); + + expect($mdDialog.hide).to.have.been.calledWith(creds); + + }); + + it('should cancel dialog when requested', () => { - }); - it('should show the login dialog when prompted', () => { + ($scope).cancelLoginDialog(); - sinon.spy($mdDialog, 'show'); + expect($mdDialog.cancel).to.have.been.called; - authService.getPromisedUser(); //@todo change this to a promptLogin() method (not yet implemented in package) + }); - expect($mdDialog.show).to.have.been.called; + it('should show the login dialog when prompted', () => { + + + authService.getPromisedUser(); //@todo change this to a promptLogin() method (not yet implemented in package) + + expect($mdDialog.show).to.have.been.called; + + }); }); + + }); }); \ No newline at end of file