@@ -42,4 +42,49 @@ describe("login", () => {
42
42
expect ( el ?. value ) . toBe ( "/hello-world" )
43
43
} )
44
44
} )
45
+ describe ( "there is not an element with id 'base'" , ( ) => {
46
+ let spy : jest . SpyInstance
47
+
48
+ beforeAll ( ( ) => {
49
+ // This is important because we're manually requiring the file
50
+ // If you don't call this before all tests
51
+ // the module registry from other tests may cause side effects.
52
+ jest . resetModuleRegistry ( )
53
+ } )
54
+
55
+ beforeEach ( ( ) => {
56
+ const dom = new JSDOM ( )
57
+ global . document = dom . window . document
58
+ spy = jest . spyOn ( document , "getElementById" )
59
+
60
+ const location : LocationLike = {
61
+ pathname : "/healthz" ,
62
+ origin : "http://localhost:8080" ,
63
+ }
64
+
65
+ global . location = location as Location
66
+ } )
67
+
68
+ afterEach ( ( ) => {
69
+ spy . mockClear ( )
70
+ jest . resetModules ( )
71
+ // Reset the global.document
72
+ global . document = undefined as any as Document
73
+ global . location = undefined as any as Location
74
+ } )
75
+
76
+ afterAll ( ( ) => {
77
+ jest . restoreAllMocks ( )
78
+ } )
79
+
80
+ it ( "should do nothing" , ( ) => {
81
+ spy . mockImplementation ( ( ) => null )
82
+ // Load file
83
+ require ( "../../../src/browser/pages/login" )
84
+
85
+ // It's called once by getOptions in the top of the file
86
+ // and then another to get the base element
87
+ expect ( spy ) . toHaveBeenCalledTimes ( 2 )
88
+ } )
89
+ } )
45
90
} )
0 commit comments