propName-test.js 1.1 KB

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