|
| 1 | +/* |
| 2 | + * Copyright (c) 2015, Facebook, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +/*global jest, describe, beforeEach, it, expect*/ |
| 12 | + |
| 13 | +jest.autoMockOff(); |
| 14 | +jest.mock('../../Documentation'); |
| 15 | + |
| 16 | +describe('defaultPropsHandler', () => { |
| 17 | + var documentation; |
| 18 | + var displayNameHandler; |
| 19 | + var expression, statement; |
| 20 | + |
| 21 | + beforeEach(() => { |
| 22 | + ({expression, statement} = require('../../../tests/utils')); |
| 23 | + documentation = new (require('../../Documentation')); |
| 24 | + displayNameHandler = require('../displayNameHandler'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('extracts the displayName', () => { |
| 28 | + var definition = expression('({displayName: "FooBar"})'); |
| 29 | + displayNameHandler(documentation, definition); |
| 30 | + expect(documentation.displayName).toBe('FooBar'); |
| 31 | + |
| 32 | + definition = statement(` |
| 33 | + class Foo { |
| 34 | + static displayName = "BarFoo"; |
| 35 | + } |
| 36 | + `); |
| 37 | + displayNameHandler(documentation, definition); |
| 38 | + expect(documentation.displayName).toBe('BarFoo'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('resolves identifiers', () => { |
| 42 | + var definition = statement(` |
| 43 | + ({displayName: name}) |
| 44 | + var name = 'abc'; |
| 45 | + `).get('expression'); |
| 46 | + displayNameHandler(documentation, definition); |
| 47 | + expect(documentation.displayName).toBe('abc'); |
| 48 | + |
| 49 | + definition = statement(` |
| 50 | + class Foo { |
| 51 | + static displayName = name; |
| 52 | + } |
| 53 | + var name = 'xyz'; |
| 54 | + `); |
| 55 | + displayNameHandler(documentation, definition); |
| 56 | + expect(documentation.displayName).toBe('xyz'); |
| 57 | + }); |
| 58 | + |
| 59 | + it('ignores non-literal names', () => { |
| 60 | + var definition = expression('({displayName: foo.bar})'); |
| 61 | + expect(() => displayNameHandler(documentation, definition)).not.toThrow(); |
| 62 | + expect(documentation.displayName).not.toBeDefined(); |
| 63 | + |
| 64 | + definition = statement(` |
| 65 | + class Foo { |
| 66 | + static displayName = foo.bar; |
| 67 | + } |
| 68 | + `); |
| 69 | + expect(() => displayNameHandler(documentation, definition)).not.toThrow(); |
| 70 | + expect(documentation.displayName).not.toBeDefined(); |
| 71 | + }); |
| 72 | + |
| 73 | + it('ignores non-literal names', () => { |
| 74 | + var definition = expression('({displayName: foo.bar})'); |
| 75 | + expect(() => displayNameHandler(documentation, definition)).not.toThrow(); |
| 76 | + expect(documentation.displayName).not.toBeDefined(); |
| 77 | + |
| 78 | + definition = statement(` |
| 79 | + class Foo { |
| 80 | + static displayName = foo.bar; |
| 81 | + } |
| 82 | + `); |
| 83 | + expect(() => displayNameHandler(documentation, definition)).not.toThrow(); |
| 84 | + expect(documentation.displayName).not.toBeDefined(); |
| 85 | + }); |
| 86 | +}); |
0 commit comments