1 | /* eslint-env mocha */
|
---|
2 | import assert from 'assert';
|
---|
3 | import { extractProp, setParserName } from '../helper';
|
---|
4 | import propName from '../../src/propName';
|
---|
5 |
|
---|
6 | describe('propName', () => {
|
---|
7 | beforeEach(() => {
|
---|
8 | setParserName('babel');
|
---|
9 | });
|
---|
10 | it('should export a function', () => {
|
---|
11 | const expected = 'function';
|
---|
12 | const actual = typeof propName;
|
---|
13 |
|
---|
14 | assert.equal(actual, expected);
|
---|
15 | });
|
---|
16 |
|
---|
17 | it('should throw an error if the argument is missing', () => {
|
---|
18 | assert.throws(() => { propName(); }, Error);
|
---|
19 | });
|
---|
20 |
|
---|
21 | it('should throw an error if the argument not a JSX node', () => {
|
---|
22 | assert.throws(() => { propName({ a: 'foo' }); }, Error);
|
---|
23 | });
|
---|
24 |
|
---|
25 | it('should return correct name for normal prop', () => {
|
---|
26 | const prop = extractProp('<div foo="bar" />');
|
---|
27 |
|
---|
28 | const expected = 'foo';
|
---|
29 | const actual = propName(prop);
|
---|
30 |
|
---|
31 | assert.equal(actual, expected);
|
---|
32 | });
|
---|
33 |
|
---|
34 | it('should return correct name for namespaced prop', () => {
|
---|
35 | const prop = extractProp('<div foo:bar="baz" />', 'foo:bar');
|
---|
36 |
|
---|
37 | const expected = 'foo:bar';
|
---|
38 | const actual = propName(prop);
|
---|
39 |
|
---|
40 | assert.equal(actual, expected);
|
---|
41 | });
|
---|
42 | });
|
---|