|
| 1 | +const j = require('jscodeshift').withParser('ts'); |
| 2 | + |
| 3 | +const { findTagName, findElementId } = require('../transform'); |
| 4 | + |
| 5 | +describe('findTagName()', () => { |
| 6 | + const TESTS = [ |
| 7 | + ['', 'div'], |
| 8 | + ["tagName: ''", ''], |
| 9 | + ["tagName: 'div'", 'div'], |
| 10 | + ["tagName: 'span'", 'span'], |
| 11 | + ["tagName: 'svg'", 'svg'], |
| 12 | + ['tagName: 5', /Unexpected `tagName` value: 5/], |
| 13 | + ['tagName: foo', /Unexpected `tagName` value: foo/], |
| 14 | + ]; |
| 15 | + |
| 16 | + for (let [input, expected] of TESTS) { |
| 17 | + test(input || 'empty', () => { |
| 18 | + let props = j(`export default {${input}};`) |
| 19 | + .find(j.ExportDefaultDeclaration) |
| 20 | + .get('declaration', 'properties'); |
| 21 | + |
| 22 | + if (expected instanceof RegExp) { |
| 23 | + expect(() => findTagName(props)).toThrow(expected); |
| 24 | + } else { |
| 25 | + expect(findTagName(props)).toEqual(expected); |
| 26 | + } |
| 27 | + }); |
| 28 | + } |
| 29 | +}); |
| 30 | + |
| 31 | +describe('findElementId()', () => { |
| 32 | + const TESTS = [ |
| 33 | + ['', null], |
| 34 | + ["elementId: ''", ''], |
| 35 | + ["elementId: 'foo'", 'foo'], |
| 36 | + ['elementId: 5', /Unexpected `elementId` value: 5/], |
| 37 | + ['elementId: foo', /Unexpected `elementId` value: foo/], |
| 38 | + ]; |
| 39 | + |
| 40 | + for (let [input, expected] of TESTS) { |
| 41 | + test(input || 'empty', () => { |
| 42 | + let props = j(`export default {${input}};`) |
| 43 | + .find(j.ExportDefaultDeclaration) |
| 44 | + .get('declaration', 'properties'); |
| 45 | + |
| 46 | + if (expected instanceof RegExp) { |
| 47 | + expect(() => findElementId(props)).toThrow(expected); |
| 48 | + } else { |
| 49 | + expect(findElementId(props)).toEqual(expected); |
| 50 | + } |
| 51 | + }); |
| 52 | + } |
| 53 | +}); |
0 commit comments