|
| 1 | +/* @flow */ |
| 2 | + |
| 3 | +import formatFunction from './formatFunction'; |
| 4 | + |
| 5 | +jest.mock('./formatReactElementNode.js', () => node => |
| 6 | + `<${node.displayName} />` |
| 7 | +); |
| 8 | + |
| 9 | +function hello() { |
| 10 | + return 1; |
| 11 | +} |
| 12 | + |
| 13 | +describe('formatFunction', () => { |
| 14 | + it('should replace a function with noRefCheck without showFunctions option', () => { |
| 15 | + expect(formatFunction(hello, {})).toEqual('function noRefCheck() {}'); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should replace a function with noRefCheck if showFunctions is false', () => { |
| 19 | + expect(formatFunction(hello, { showFunctions: false })).toEqual( |
| 20 | + 'function noRefCheck() {}' |
| 21 | + ); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should format a function if showFunctions is true', () => { |
| 25 | + expect(formatFunction(hello, { showFunctions: true })) |
| 26 | + .toEqual(`function hello() { |
| 27 | + return 1; |
| 28 | +}`); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should format a function without name if showFunctions is true', () => { |
| 32 | + expect(formatFunction(() => 1, { showFunctions: true })).toEqual( |
| 33 | + 'function () {return 1;}' |
| 34 | + ); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should use the functionValue option', () => { |
| 38 | + expect(formatFunction(hello, { functionValue: () => '<Test />' })).toEqual( |
| 39 | + '<Test />' |
| 40 | + ); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should use the functionValue option even if showFunctions is true', () => { |
| 44 | + expect( |
| 45 | + formatFunction(hello, { |
| 46 | + showFunctions: true, |
| 47 | + functionValue: () => '<Test />', |
| 48 | + }) |
| 49 | + ).toEqual('<Test />'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should use the functionValue option even if showFunctions is false', () => { |
| 53 | + expect( |
| 54 | + formatFunction(hello, { |
| 55 | + showFunctions: false, |
| 56 | + functionValue: () => '<Test />', |
| 57 | + }) |
| 58 | + ).toEqual('<Test />'); |
| 59 | + }); |
| 60 | +}); |
0 commit comments