Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit f9805d1

Browse files
committed
Tests: Refactoring in FocusCycler tests.
1 parent 961d619 commit f9805d1

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

tests/focuscycler.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,9 @@ describe( 'FocusCycler', () => {
202202

203203
describe( 'focusFirst()', () => {
204204
it( 'focuses first focusable view', () => {
205-
const spy = sinon.spy( focusables.get( 1 ), 'focus' );
206-
207205
cycler.focusFirst();
208206

209-
sinon.assert.calledOnce( spy );
207+
sinon.assert.calledOnce( focusables.get( 1 ).focus );
210208
} );
211209

212210
it( 'does not throw when no focusable items', () => {
@@ -232,7 +230,6 @@ describe( 'FocusCycler', () => {
232230

233231
it( 'ignores invisible items', () => {
234232
const item = focusable();
235-
const spy = sinon.spy( item, 'focus' );
236233

237234
focusables = new ViewCollection();
238235
focusables.add( nonFocusable() );
@@ -242,17 +239,15 @@ describe( 'FocusCycler', () => {
242239
cycler = new FocusCycler( { focusables, focusTracker } );
243240

244241
cycler.focusFirst();
245-
sinon.assert.calledOnce( spy );
242+
sinon.assert.calledOnce( item.focus );
246243
} );
247244
} );
248245

249246
describe( 'focusLast()', () => {
250247
it( 'focuses last focusable view', () => {
251-
const spy = sinon.spy( focusables.get( 3 ), 'focus' );
252-
253248
cycler.focusLast();
254249

255-
sinon.assert.calledOnce( spy );
250+
sinon.assert.calledOnce( focusables.get( 3 ).focus );
256251
} );
257252

258253
it( 'does not throw when no focusable items', () => {
@@ -279,12 +274,10 @@ describe( 'FocusCycler', () => {
279274

280275
describe( 'focusNext()', () => {
281276
it( 'focuses next focusable view', () => {
282-
const spy = sinon.spy( focusables.get( 3 ), 'focus' );
283-
284277
focusTracker.focusedElement = focusables.get( 2 ).element;
285278
cycler.focusNext();
286279

287-
sinon.assert.calledOnce( spy );
280+
sinon.assert.calledOnce( focusables.get( 3 ).focus );
288281
} );
289282

290283
it( 'does not throw when no focusable items', () => {
@@ -311,12 +304,10 @@ describe( 'FocusCycler', () => {
311304

312305
describe( 'focusPrevious()', () => {
313306
it( 'focuses previous focusable view', () => {
314-
const spy = sinon.spy( focusables.get( 3 ), 'focus' );
315-
316307
focusTracker.focusedElement = focusables.get( 1 ).element;
317308
cycler.focusPrevious();
318309

319-
sinon.assert.calledOnce( spy );
310+
sinon.assert.calledOnce( focusables.get( 3 ).focus );
320311
} );
321312

322313
it( 'does not throw when no focusable items', () => {
@@ -422,7 +413,7 @@ function nonFocusable( isHidden ) {
422413
function focusable( isHidden ) {
423414
const view = nonFocusable( isHidden );
424415

425-
view.focus = () => {};
416+
view.focus = sinon.spy();
426417

427418
return view;
428419
}

0 commit comments

Comments
 (0)