test: 💍 add missing test for component without script

This commit is contained in:
Christian Kaisermann 2019-11-28 23:16:15 -03:00
parent 45216d46ea
commit e08fa29099
3 changed files with 11 additions and 6 deletions

View File

@ -150,10 +150,7 @@ export function collectMessages(markup: string): Message[] {
return messageObj
}
return {
node,
meta: { id },
}
return { node, meta: { id } }
}),
].filter(Boolean)
}

View File

@ -5,9 +5,11 @@ import { Message } from '../types'
export function getObjFromExpression(exprNode: ObjectExpression) {
return exprNode.properties.reduce<Message>(
(acc, prop: Property) => {
if (prop.value.type !== 'Literal') return acc
// we only want primitives
if (prop.value.value !== Object(prop.value.value)) {
if (
prop.value.type === 'Literal' &&
prop.value.value !== Object(prop.value.value)
) {
const key = (prop.key as Identifier).name as string
acc.meta[key] = prop.value.value
}

View File

@ -10,6 +10,12 @@ import {
} from '../../src/cli/extract'
describe('collecting format calls', () => {
test('returns nothing if there are no script tag', () => {
const ast = parse(`<div>Hey</div>`)
const calls = collectFormatCalls(ast)
expect(calls).toHaveLength(0)
})
test('returns nothing if there are no imports', () => {
const ast = parse(`<script>
import Foo from 'foo';