Sha256: 0645a09a24382c943ed7907e8f79358a094180026ea15c5003c471ffdc2666db

Contents?: true

Size: 1.08 KB

Versions: 15

Compression:

Stored size: 1.08 KB

Contents

/* eslint-env mocha */
import assert from 'assert';
import { extractProp, setParserName } from '../helper';
import propName from '../../src/propName';

describe('propName', () => {
  beforeEach(() => {
    setParserName('babel');
  });
  it('should export a function', () => {
    const expected = 'function';
    const actual = typeof propName;

    assert.equal(expected, actual);
  });

  it('should throw an error if the argument is missing', () => {
    assert.throws(() => { propName(); }, Error);
  });

  it('should throw an error if the argument not a JSX node', () => {
    assert.throws(() => { propName({ a: 'foo' }); }, Error);
  });

  it('should return correct name for normal prop', () => {
    const prop = extractProp('<div foo="bar" />');

    const expected = 'foo';
    const actual = propName(prop);

    assert.equal(expected, actual);
  });

  it('should return correct name for namespaced prop', () => {
    const prop = extractProp('<div foo:bar="baz" />', 'foo:bar');

    const expected = 'foo:bar';
    const actual = propName(prop);

    assert.equal(expected, actual);
  });
});

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.21.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.20.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.19.1 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.19.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.18.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.17.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.16.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.15.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.14.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.13.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.12.2 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.12.1 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.12.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js
govuk_publishing_components-17.11.0 node_modules/jsx-ast-utils/__tests__/src/propName-test.js