/* eslint-env mocha */ /* eslint no-template-curly-in-string: 0 */ import assert from 'assert'; import { extractProp, changePlugins, fallbackToBabylon } from '../helper'; import getPropValue from '../../src/getPropValue'; const describeIfNotBabylon = fallbackToBabylon ? describe.skip : describe; describe('getPropValue', () => { it('should export a function', () => { const expected = 'function'; const actual = typeof getPropValue; assert.equal(expected, actual); }); it('should return undefined when not provided with a JSXAttribute', () => { const expected = undefined; const actual = getPropValue(1); assert.equal(expected, actual); }); it('should throw error when trying to get value from unknown node type', () => { const prop = { type: 'JSXAttribute', value: { type: 'JSXExpressionContainer', }, }; assert.throws(() => { getPropValue(prop); }, Error); }); describe('Null', () => { it('should return true when no value is given', () => { const prop = extractProp('
'); const expected = true; const actual = getPropValue(prop); assert.equal(expected, actual); }); }); describe('Literal', () => { it('should return correct string if value is a string', () => { const prop = extractProp(''); const expected = 'bar'; const actual = getPropValue(prop); assert.equal(expected, actual); }); it('should return correct string if value is a string expression', () => { const prop = extractProp(''); const expected = 'bar'; const actual = getPropValue(prop); assert.equal(expected, actual); }); it('should return correct integer if value is a integer expression', () => { const prop = extractProp(''); const expected = 1; const actual = getPropValue(prop); assert.equal(expected, actual); }); it('should convert "true" to boolean type', () => { const prop = extractProp(''); const expected = true; const actual = getPropValue(prop); assert.equal(expected, actual); }); it('should convert "false" to boolean type', () => { const prop = extractProp(''); const expected = false; const actual = getPropValue(prop); assert.equal(expected, actual); }); }); describe('JSXElement', () => { it('should return correct representation of JSX element as a string', () => { const prop = extractProp(' />'); const expected = '