1- const Tram = window [ 'tram-one' ]
2- const testemPath = window . location . pathname
1+ const Tram = require ( '../../dist/tram-one.esm' )
2+
3+ const isBrowser = typeof window !== 'undefined'
4+ const testemPath = isBrowser ? window . location . pathname : '/'
5+ const document = isBrowser ? window . document : require ( 'min-document' )
6+
7+ const stringify = ( node ) => {
8+ if ( node . outerHTML !== undefined ) {
9+ return node . outerHTML
10+ }
11+ return node . toString ( )
12+ }
313
414describe ( 'Tram' , ( ) => {
515 let app
@@ -23,22 +33,22 @@ describe('Tram', () => {
2333 app = new Tram ( )
2434
2535 app . addRoute ( '/404' , errorPage )
26- expect ( app . toString ( '/' ) ) . toEqual ( errorPage ( ) . outerHTML )
36+ expect ( app . toString ( '/' ) ) . toEqual ( stringify ( errorPage ( ) ) )
2737 } )
2838
2939 it ( 'should take in a default route' , ( ) => {
3040 app = new Tram ( { defaultRoute : '/200' } )
3141
3242 app . addRoute ( '/200' , successPage )
33- expect ( app . toString ( '/' ) ) . toEqual ( successPage ( ) . outerHTML )
43+ expect ( app . toString ( '/' ) ) . toEqual ( stringify ( successPage ( ) ) )
3444 } )
3545
3646 it ( 'should not always go to the default' , ( ) => {
3747 app = new Tram ( )
3848
3949 app . addRoute ( '/404' , errorPage )
4050 app . addRoute ( '/200' , successPage )
41- expect ( app . toString ( '/200' ) ) . not . toEqual ( errorPage ( ) . outerHTML )
51+ expect ( app . toString ( '/200' ) ) . not . toEqual ( stringify ( errorPage ( ) ) )
4252 } )
4353 } )
4454
@@ -63,10 +73,10 @@ describe('Tram', () => {
6373 app . addRoute ( '/good' , successPage )
6474 app . addRoute ( '/bad' , errorPage )
6575 app . addRoute ( '/404' , errorPage )
66- expect ( app . toString ( '/' ) ) . toEqual ( successPage ( ) . outerHTML )
67- expect ( app . toString ( '/good' ) ) . toEqual ( successPage ( ) . outerHTML )
68- expect ( app . toString ( '/bad' ) ) . toEqual ( errorPage ( ) . outerHTML )
69- expect ( app . toString ( '/404' ) ) . toEqual ( errorPage ( ) . outerHTML )
76+ expect ( app . toString ( '/' ) ) . toEqual ( stringify ( successPage ( ) ) )
77+ expect ( app . toString ( '/good' ) ) . toEqual ( stringify ( successPage ( ) ) )
78+ expect ( app . toString ( '/bad' ) ) . toEqual ( stringify ( errorPage ( ) ) )
79+ expect ( app . toString ( '/404' ) ) . toEqual ( stringify ( errorPage ( ) ) )
7080 } )
7181
7282 it ( 'should include the default state in app' , ( ) => {
@@ -86,6 +96,8 @@ describe('Tram', () => {
8696 } )
8797
8898 describe ( 'start' , ( ) => {
99+ if ( ! isBrowser ) { return }
100+
89101 beforeEach ( ( ) => {
90102 const childDiv = document . createElement ( 'div' )
91103 childDiv . id = 'tram_test_container'
@@ -120,6 +132,8 @@ describe('Tram', () => {
120132 } )
121133
122134 describe ( 'mount' , ( ) => {
135+ if ( ! isBrowser ) { return }
136+
123137 beforeEach ( ( ) => {
124138 const childDiv = document . createElement ( 'div' )
125139 childDiv . id = 'tram_test_container'
@@ -136,9 +150,9 @@ describe('Tram', () => {
136150
137151 app . addRoute ( '/' , queryablePage )
138152 const target = document . getElementById ( 'tram_test_container' )
139- app . mount ( target , '/' )
153+ app . mount ( target , '/' , undefined , document )
140154 const mountedTarget = document . querySelector ( queryableSelector )
141- expect ( mountedTarget . outerHTML ) . toEqual ( queryablePage ( ) . outerHTML )
155+ expect ( mountedTarget . outerHTML ) . toEqual ( stringify ( queryablePage ( ) ) )
142156 } )
143157
144158 it ( 'should use the default route' , ( ) => {
@@ -149,7 +163,7 @@ describe('Tram', () => {
149163 const target = document . getElementById ( 'tram_test_container' )
150164 app . mount ( target )
151165 const mountedTarget = document . querySelector ( queryableSelector )
152- expect ( mountedTarget . outerHTML ) . toEqual ( queryablePage ( 200 ) . outerHTML )
166+ expect ( mountedTarget . outerHTML ) . toEqual ( stringify ( queryablePage ( 200 ) ) )
153167 } )
154168
155169 it ( 'should attach the app to a selector' , ( ) => {
@@ -158,7 +172,7 @@ describe('Tram', () => {
158172 app . addRoute ( '/' , queryablePage )
159173 app . mount ( '#tram_test_container' , '/' )
160174 const mountedTarget = document . querySelector ( queryableSelector )
161- expect ( mountedTarget . outerHTML ) . toEqual ( queryablePage ( ) . outerHTML )
175+ expect ( mountedTarget . outerHTML ) . toEqual ( stringify ( queryablePage ( ) ) )
162176 } )
163177
164178 it ( 'should update the app on re-mount' , ( ) => {
@@ -169,15 +183,15 @@ describe('Tram', () => {
169183 app . mount ( '#tram_test_container' , '/' )
170184 app . mount ( '#tram_test_container' , '/200' )
171185 const mountedTarget = document . querySelector ( queryableSelector )
172- expect ( mountedTarget . outerHTML ) . toEqual ( queryablePage ( 200 ) . outerHTML )
186+ expect ( mountedTarget . outerHTML ) . toEqual ( stringify ( queryablePage ( 200 ) ) )
173187 } )
174188 } )
175189
176190 describe ( 'toNode' , ( ) => {
177191 it ( 'should resolve the path' , ( ) => {
178192 app = new Tram ( )
179193 app . addRoute ( '/' , successPage )
180- expect ( app . toNode ( '/' ) . outerHTML ) . toEqual ( successPage ( ) . outerHTML )
194+ expect ( stringify ( app . toNode ( '/' ) ) ) . toEqual ( stringify ( successPage ( ) ) )
181195 } )
182196
183197 it ( 'should have the default state' , ( ) => {
@@ -198,7 +212,7 @@ describe('Tram', () => {
198212 it ( 'should return a string' , ( ) => {
199213 app = new Tram ( )
200214 app . addRoute ( '/404' , errorPage )
201- expect ( app . toString ( '/' ) ) . toEqual ( errorPage ( ) . outerHTML )
215+ expect ( app . toString ( '/' ) ) . toEqual ( stringify ( errorPage ( ) ) )
202216 } )
203217 } )
204218
0 commit comments