@@ -24,13 +24,26 @@ const EditorState = require('EditorState');
2424const SelectionState = require ( 'SelectionState' ) ;
2525
2626const getSampleStateForTesting = require ( 'getSampleStateForTesting' ) ;
27+ const invariant = require ( 'invariant' ) ;
2728
2829const { editorState, contentState, selectionState} = getSampleStateForTesting ( ) ;
2930
3031const initialBlock = contentState . getBlockMap ( ) . first ( ) ;
3132const ENTITY_KEY = Entity . create ( 'TOKEN' , 'MUTABLE' ) ;
3233const CHARACTER = ' ' ;
3334
35+ const getInvariantViolation = msg => {
36+ try {
37+ /* eslint-disable fb-www/sprintf-like-args */
38+ invariant ( false , msg ) ;
39+ /* eslint-enable fb-www/sprintf-like-args */
40+ } catch ( e ) {
41+ return e ;
42+ }
43+
44+ throw new Error ( 'We should never reach here!' ) ;
45+ } ;
46+
3447const toggleExperimentalTreeDataSupport = enabled => {
3548 jest . doMock ( 'gkx' , ( ) => name => {
3649 return name === 'draft_tree_data_support' ? enabled : false ;
@@ -251,7 +264,7 @@ test("mustn't move atomic next to itself with collapsed selection", () => {
251264 focusOffset : beforeAtomicBlock . getLength ( ) ,
252265 } ) ,
253266 ) ;
254- } ) . toThrow ( new Error ( 'Block cannot be moved next to itself.' ) ) ;
267+ } ) . toThrow ( getInvariantViolation ( 'Block cannot be moved next to itself.' ) ) ;
255268
256269 // Move atomic block above itself by moving it after preceding block
257270 expect ( ( ) => {
@@ -264,7 +277,7 @@ test("mustn't move atomic next to itself with collapsed selection", () => {
264277 } ) ,
265278 'after' ,
266279 ) ;
267- } ) . toThrow ( new Error ( 'Block cannot be moved next to itself.' ) ) ;
280+ } ) . toThrow ( getInvariantViolation ( 'Block cannot be moved next to itself.' ) ) ;
268281
269282 // Move atomic block above itself by replacement
270283 expect ( ( ) => {
@@ -278,7 +291,7 @@ test("mustn't move atomic next to itself with collapsed selection", () => {
278291 focusOffset : atomicBlock . getLength ( ) ,
279292 } ) ,
280293 ) ;
281- } ) . toThrow ( new Error ( 'Block cannot be moved next to itself.' ) ) ;
294+ } ) . toThrow ( getInvariantViolation ( 'Block cannot be moved next to itself.' ) ) ;
282295
283296 // Move atomic block above itself
284297 expect ( ( ) => {
@@ -290,7 +303,7 @@ test("mustn't move atomic next to itself with collapsed selection", () => {
290303 } ) ,
291304 'before' ,
292305 ) ;
293- } ) . toThrow ( new Error ( 'Block cannot be moved next to itself.' ) ) ;
306+ } ) . toThrow ( getInvariantViolation ( 'Block cannot be moved next to itself.' ) ) ;
294307
295308 // Move atomic block below itself by moving it before following block by replacement
296309 expect ( ( ) => {
@@ -302,7 +315,7 @@ test("mustn't move atomic next to itself with collapsed selection", () => {
302315 focusKey : afterAtomicBlock . getKey ( ) ,
303316 } ) ,
304317 ) ;
305- } ) . toThrow ( new Error ( 'Block cannot be moved next to itself.' ) ) ;
318+ } ) . toThrow ( getInvariantViolation ( 'Block cannot be moved next to itself.' ) ) ;
306319
307320 // Move atomic block below itself by moving it before following block
308321 expect ( ( ) => {
@@ -315,7 +328,7 @@ test("mustn't move atomic next to itself with collapsed selection", () => {
315328 } ) ,
316329 'before' ,
317330 ) ;
318- } ) . toThrow ( new Error ( 'Block cannot be moved next to itself.' ) ) ;
331+ } ) . toThrow ( getInvariantViolation ( 'Block cannot be moved next to itself.' ) ) ;
319332
320333 // Move atomic block below itself by replacement
321334 expect ( ( ) => {
@@ -329,7 +342,7 @@ test("mustn't move atomic next to itself with collapsed selection", () => {
329342 focusOffset : atomicBlock . getLength ( ) ,
330343 } ) ,
331344 ) ;
332- } ) . toThrow ( new Error ( 'Block cannot be moved next to itself.' ) ) ;
345+ } ) . toThrow ( getInvariantViolation ( 'Block cannot be moved next to itself.' ) ) ;
333346
334347 // Move atomic block below itself
335348 expect ( ( ) => {
@@ -341,7 +354,7 @@ test("mustn't move atomic next to itself with collapsed selection", () => {
341354 } ) ,
342355 'after' ,
343356 ) ;
344- } ) . toThrow ( new Error ( 'Block cannot be moved next to itself.' ) ) ;
357+ } ) . toThrow ( getInvariantViolation ( 'Block cannot be moved next to itself.' ) ) ;
345358} ) ;
346359
347360/**
@@ -558,7 +571,7 @@ test("mustn't move atomic next to itself", () => {
558571 focusOffset : beforeAtomicBlock . getLength ( ) ,
559572 } ) ,
560573 ) ;
561- } ) . toThrow ( new Error ( 'Block cannot be moved next to itself.' ) ) ;
574+ } ) . toThrow ( getInvariantViolation ( 'Block cannot be moved next to itself.' ) ) ;
562575
563576 // Move atomic block below itself by moving it before following block by
564577 // replacement
@@ -573,7 +586,7 @@ test("mustn't move atomic next to itself", () => {
573586 focusOffset : 2 ,
574587 } ) ,
575588 ) ;
576- } ) . toThrow ( new Error ( 'Block cannot be moved next to itself.' ) ) ;
589+ } ) . toThrow ( getInvariantViolation ( 'Block cannot be moved next to itself.' ) ) ;
577590} ) ;
578591
579592test ( 'must be able to insert atomic block when experimentalTreeDataSupport is enabled' , ( ) => {
0 commit comments