| 1 | import test from 'tape';
|
|---|
| 2 |
|
|---|
| 3 | import isNonLiteralProperty from '../../../src/util/isNonLiteralProperty';
|
|---|
| 4 | import IdentifierMock from '../../../__mocks__/IdentifierMock';
|
|---|
| 5 | import JSXAttributeMock from '../../../__mocks__/JSXAttributeMock';
|
|---|
| 6 | import JSXSpreadAttributeMock from '../../../__mocks__/JSXSpreadAttributeMock';
|
|---|
| 7 | import JSXTextMock from '../../../__mocks__/JSXTextMock';
|
|---|
| 8 | import LiteralMock from '../../../__mocks__/LiteralMock';
|
|---|
| 9 |
|
|---|
| 10 | const theProp = 'theProp';
|
|---|
| 11 |
|
|---|
| 12 | const spread = JSXSpreadAttributeMock('theSpread');
|
|---|
| 13 |
|
|---|
| 14 | test('isNonLiteralProperty', (t) => {
|
|---|
| 15 | t.equal(
|
|---|
| 16 | isNonLiteralProperty([], theProp),
|
|---|
| 17 | false,
|
|---|
| 18 | 'does not identify them as non-literal role elements',
|
|---|
| 19 | );
|
|---|
| 20 |
|
|---|
| 21 | t.equal(
|
|---|
| 22 | isNonLiteralProperty([JSXAttributeMock(theProp, LiteralMock('theRole'))], theProp),
|
|---|
| 23 | false,
|
|---|
| 24 | 'does not identify elements with a literal property as non-literal role elements without spread operator',
|
|---|
| 25 | );
|
|---|
| 26 |
|
|---|
| 27 | t.equal(
|
|---|
| 28 | isNonLiteralProperty([spread, JSXAttributeMock(theProp, LiteralMock('theRole'))], theProp),
|
|---|
| 29 | false,
|
|---|
| 30 | 'does not identify elements with a literal property as non-literal role elements with spread operator',
|
|---|
| 31 | );
|
|---|
| 32 |
|
|---|
| 33 | t.equal(
|
|---|
| 34 | isNonLiteralProperty([JSXAttributeMock(theProp, JSXTextMock('theRole'))], theProp),
|
|---|
| 35 | false,
|
|---|
| 36 | 'identifies elements with a JSXText property as non-literal role elements',
|
|---|
| 37 | );
|
|---|
| 38 |
|
|---|
| 39 | t.equal(
|
|---|
| 40 | isNonLiteralProperty([JSXAttributeMock(theProp, IdentifierMock('undefined'))], theProp),
|
|---|
| 41 | false,
|
|---|
| 42 | 'does not identify elements with a property of undefined as non-literal role elements',
|
|---|
| 43 | );
|
|---|
| 44 |
|
|---|
| 45 | t.equal(
|
|---|
| 46 | isNonLiteralProperty([JSXAttributeMock(theProp, IdentifierMock('theIdentifier'))], theProp),
|
|---|
| 47 | true,
|
|---|
| 48 | 'identifies elements with an expression property as non-literal role elements',
|
|---|
| 49 | );
|
|---|
| 50 |
|
|---|
| 51 | t.end();
|
|---|
| 52 | });
|
|---|