@@ -302,4 +302,70 @@ describe('CodeListing', () => {
302
302
303
303
expect ( wrapper . classes ( ) ) . toContain ( 'single-line' ) ;
304
304
} ) ;
305
+
306
+ it ( 'does not wrap when wrap=0' , async ( ) => {
307
+ const wrapper = shallowMount ( CodeListing , {
308
+ propsData : {
309
+ syntax : 'swift' ,
310
+ content : [ 'let foo = "bar"' ] ,
311
+ wrap : 0 ,
312
+ } ,
313
+ } ) ;
314
+ await flushPromises ( ) ;
315
+
316
+ expect ( wrapper . classes ( ) ) . not . toContain ( 'is-wrapped' ) ;
317
+
318
+ const style = wrapper . attributes ( 'style' ) || '' ;
319
+ expect ( style ) . not . toMatch ( / - - w r a p - c h : \s * \d + / ) ;
320
+ } ) ;
321
+
322
+ it ( 'wraps when wrap>0 and exposes the width in style' , async ( ) => {
323
+ const wrapper = shallowMount ( CodeListing , {
324
+ propsData : {
325
+ syntax : 'swift' ,
326
+ content : [ 'let foo = "bar"' ] ,
327
+ wrap : 80 ,
328
+ } ,
329
+ } ) ;
330
+ await flushPromises ( ) ;
331
+
332
+ expect ( wrapper . classes ( ) ) . toContain ( 'is-wrapped' ) ;
333
+
334
+ const style = wrapper . attributes ( 'style' ) || '' ;
335
+ expect ( style ) . toMatch ( / - - w r a p - c h : \s * 8 0 \b / ) ;
336
+ } ) ;
337
+
338
+ it ( 'reacts when wrap changes' , async ( ) => {
339
+ const wrapper = shallowMount ( CodeListing , {
340
+ propsData : {
341
+ syntax : 'swift' ,
342
+ content : [ 'let foo = "bar"' ] ,
343
+ wrap : 80 ,
344
+ } ,
345
+ } ) ;
346
+ await flushPromises ( ) ;
347
+
348
+ expect ( wrapper . classes ( ) ) . toContain ( 'is-wrapped' ) ;
349
+
350
+ let style = wrapper . attributes ( 'style' ) || '' ;
351
+ expect ( style ) . toMatch ( / - - w r a p - c h : \s * 8 0 \b / ) ;
352
+
353
+ await wrapper . setProps ( { wrap : 0 } ) ;
354
+ style = wrapper . attributes ( 'style' ) || '' ;
355
+ expect ( wrapper . classes ( ) ) . not . toContain ( 'is-wrapped' ) ;
356
+ expect ( style ) . not . toMatch ( / - - w r a p - c h : \s * \d + / ) ;
357
+ } ) ;
358
+
359
+ it ( 'treats negative wrap as no-wrap' , async ( ) => {
360
+ const wrapper = shallowMount ( CodeListing , {
361
+ propsData : {
362
+ syntax : 'swift' ,
363
+ content : [ 'let foo = "bar"' ] ,
364
+ wrap : - 5 ,
365
+ } ,
366
+ } ) ;
367
+ await flushPromises ( ) ;
368
+
369
+ expect ( wrapper . classes ( ) ) . not . toContain ( 'is-wrapped' ) ;
370
+ } ) ;
305
371
} ) ;
0 commit comments