11import SpatialNavigation from '../src/spatial-navigation' ;
22
33describe ( 'SpatialNavigation' , ( ) => {
4- describe ( 'initialize' , ( ) => {
5- let setStateSpy ;
4+ let setStateSpy ;
65
7- beforeEach ( ( ) => {
8- setStateSpy = jest . fn ( ) ;
9- SpatialNavigation . init ( setStateSpy ) ;
10- } ) ;
6+ beforeEach ( ( ) => {
7+ setStateSpy = jest . fn ( ) ;
8+ SpatialNavigation . init ( setStateSpy ) ;
9+ } ) ;
1110
11+ afterEach ( ( ) => {
12+ SpatialNavigation . destroy ( ) ;
13+ } ) ;
14+
15+ describe ( 'on initialize' , ( ) => {
1216 it ( 'listens to sn:focused event' , ( ) => {
1317 const event = new CustomEvent ( 'sn:focused' , {
1418 detail : { sectionId : 'focusPath' } ,
@@ -20,7 +24,7 @@ describe('SpatialNavigation', () => {
2024
2125 describe ( 'when focusing the same focused element' , ( ) => {
2226 beforeEach ( ( ) => {
23- SpatialNavigation . focused = 'focusPath' ;
27+ SpatialNavigation . focusedPath = 'focusPath' ;
2428 } ) ;
2529
2630 it ( 'does nothing' , ( ) => {
@@ -34,7 +38,16 @@ describe('SpatialNavigation', () => {
3438 } ) ;
3539 } ) ;
3640
37- describe ( 'destroy' , ( ) => {
41+ describe ( 'on destroy' , ( ) => {
42+ it ( 'stops listening to sn:focused' , ( ) => {
43+ SpatialNavigation . destroy ( ) ;
44+
45+ const event = new CustomEvent ( 'sn:focused' , {
46+ detail : { sectionId : 'focusPath' } ,
47+ } ) ;
48+ document . dispatchEvent ( event ) ;
3849
50+ expect ( setStateSpy ) . not . toHaveBeenCalled ( ) ;
51+ } ) ;
3952 } ) ;
4053} ) ;
0 commit comments