File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest'
2+ import { mountSuspended } from '@nuxt/test-utils/runtime'
3+ import CodeViewer from '~/components/Code/Viewer.vue'
4+
5+ const SAMPLE_HTML = '<code><span class="line">const x = 1</span></code>'
6+
7+ describe ( 'CodeViewer' , ( ) => {
8+ it ( 'renders when given html and line count' , async ( ) => {
9+ const wrapper = await mountSuspended ( CodeViewer , {
10+ props : {
11+ html : SAMPLE_HTML ,
12+ lines : 1 ,
13+ selectedLines : null ,
14+ wordWrap : false ,
15+ } ,
16+ } )
17+
18+ expect ( wrapper . find ( 'pre' ) . exists ( ) || wrapper . html ( ) . includes ( 'line' ) ) . toBe ( true )
19+ } )
20+
21+ it ( 'applies word-wrap class to pre element when wordWrap prop is true' , async ( ) => {
22+ const wrapper = await mountSuspended ( CodeViewer , {
23+ props : {
24+ html : SAMPLE_HTML ,
25+ lines : 1 ,
26+ selectedLines : null ,
27+ wordWrap : true ,
28+ } ,
29+ } )
30+
31+ const html = wrapper . html ( )
32+ // When wordWrap is true, the code-lines div should have the 'word-wrap' class
33+ expect ( html ) . toContain ( 'word-wrap' )
34+ } )
35+
36+ it ( 'does not apply word-wrap class when wordWrap prop is false' , async ( ) => {
37+ const wrapper = await mountSuspended ( CodeViewer , {
38+ props : {
39+ html : SAMPLE_HTML ,
40+ lines : 1 ,
41+ selectedLines : null ,
42+ wordWrap : false ,
43+ } ,
44+ } )
45+
46+ const codeLines = wrapper . find ( '.code-lines' )
47+ // Without word wrap, the code-lines div should NOT have the 'word-wrap' class
48+ expect ( codeLines . classes ( ) ) . not . toContain ( 'word-wrap' )
49+ } )
50+ } )
You can’t perform that action at this time.
0 commit comments