@@ -2,11 +2,22 @@ describe('Cell', function () {
2
2
const colors = require ( '@colors/colors' ) ;
3
3
const Cell = require ( '../src/cell' ) ;
4
4
const { ColSpanCell, RowSpanCell } = Cell ;
5
- const { mergeOptions } = require ( '../src/utils' ) ;
5
+ const utils = require ( '../src/utils' ) ;
6
+ const { wordWrap : actualWordWrap } = jest . requireActual ( '../src/utils' ) ;
7
+
8
+ jest . mock ( '../src/utils' , ( ) => ( {
9
+ ...jest . requireActual ( '../src/utils' ) ,
10
+ wordWrap : jest . fn ( ) , // only mock this
11
+ } ) ) ;
12
+
13
+ beforeEach ( ( ) => {
14
+ // use the default implementation, unless we override
15
+ utils . wordWrap . mockImplementation ( ( ...args ) => actualWordWrap ( ...args ) ) ;
16
+ } ) ;
6
17
7
18
function defaultOptions ( ) {
8
19
//overwrite coloring of head and border by default for easier testing.
9
- return mergeOptions ( { style : { head : [ ] , border : [ ] } } ) ;
20
+ return utils . mergeOptions ( { style : { head : [ ] , border : [ ] } } ) ;
10
21
}
11
22
12
23
function defaultChars ( ) {
@@ -89,6 +100,69 @@ describe('Cell', function () {
89
100
} ) ;
90
101
91
102
describe ( 'mergeTableOptions' , function ( ) {
103
+ describe ( 'wordwrap' , function ( ) {
104
+ let tableOptions , cell ;
105
+
106
+ function initCell ( { wordWrap, wrapOnWordBoundary } = { } ) {
107
+ cell = new Cell ( { content : 'some text' , wordWrap, wrapOnWordBoundary } ) ;
108
+ cell . x = cell . y = 0 ;
109
+ }
110
+
111
+ beforeEach ( ( ) => {
112
+ utils . wordWrap . mockClear ( ) ;
113
+ tableOptions = { ...defaultOptions ( ) , colWidths : [ 50 ] } ;
114
+ } ) ;
115
+
116
+ it ( 'no cell wordWrap override (tableOptions.wordWrap=true)' , function ( ) {
117
+ tableOptions . wordWrap = true ; // wrapOnWordBoundary is true by default
118
+ initCell ( ) ;
119
+
120
+ cell . mergeTableOptions ( tableOptions ) ;
121
+ expect ( utils . wordWrap ) . toHaveBeenCalledWith ( expect . any ( Number ) , cell . content , true /*wrapOnWordBoundary*/ ) ;
122
+ } ) ;
123
+
124
+ it ( 'no cell wordWrap override (tableOptions.wordWrap=false)' , function ( ) {
125
+ tableOptions . wordWrap = false ; // wrapOnWordBoundary is true by default
126
+ initCell ( ) ;
127
+
128
+ cell . mergeTableOptions ( tableOptions ) ;
129
+ expect ( utils . wordWrap ) . not . toHaveBeenCalled ( ) ;
130
+ } ) ;
131
+
132
+ it ( 'cell wordWrap override (cell.options.wordWrap=false)' , function ( ) {
133
+ tableOptions . wordWrap = true ; // wrapOnWordBoundary is true by default
134
+ initCell ( { wordWrap : false } ) ;
135
+
136
+ cell . mergeTableOptions ( tableOptions ) ;
137
+ expect ( utils . wordWrap ) . not . toHaveBeenCalled ( ) ; // no wrapping done
138
+ } ) ;
139
+
140
+ it ( 'cell wordWrap override (cell.options.wordWrap=true)' , function ( ) {
141
+ tableOptions . wordWrap = false ; // wrapOnWordBoundary is true by default
142
+ initCell ( { wordWrap : true } ) ;
143
+
144
+ cell . mergeTableOptions ( tableOptions ) ;
145
+ expect ( utils . wordWrap ) . toHaveBeenCalled ( ) ;
146
+ } ) ;
147
+
148
+ it ( 'cell wrapOnWordBoundary override (cell.options.wrapOnWordBoundary=false)' , function ( ) {
149
+ tableOptions . wordWrap = true ; // wrapOnWordBoundary is true by default
150
+ initCell ( { wrapOnWordBoundary : false } ) ;
151
+
152
+ cell . mergeTableOptions ( tableOptions ) ;
153
+ expect ( utils . wordWrap ) . toHaveBeenCalledWith ( expect . any ( Number ) , cell . content , false /*wrapOnWordBoundary*/ ) ;
154
+ } ) ;
155
+
156
+ it ( 'cell wrapOnWordBoundary override (cell.options.wrapOnWordBoundary=true)' , function ( ) {
157
+ tableOptions . wordWrap = true ;
158
+ tableOptions . wrapOnWordBoundary = false ;
159
+ initCell ( { wrapOnWordBoundary : true } ) ;
160
+
161
+ cell . mergeTableOptions ( tableOptions ) ;
162
+ expect ( utils . wordWrap ) . toHaveBeenCalledWith ( expect . any ( Number ) , cell . content , true /*wrapOnWordBoundary*/ ) ;
163
+ } ) ;
164
+ } ) ;
165
+
92
166
describe ( 'chars' , function ( ) {
93
167
it ( 'unset chars take on value of table' , function ( ) {
94
168
let cell = new Cell ( ) ;
0 commit comments