Skip to content

Commit

Permalink
fix(directive): fix localization when element does not have attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Demivan committed Aug 8, 2019
1 parent d395b42 commit a3581fd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/directive.ts
Expand Up @@ -20,9 +20,6 @@ export default {
}

el.textContent = vnode.context.$fluent.formatPattern(msg.value, binding.value)
if (vnode.data === undefined || vnode.data.attrs === undefined) {
return
}

for (const [attr] of Object.entries(binding.modifiers)) {
el.setAttribute(
Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/directive.test.ts.snap
Expand Up @@ -7,3 +7,5 @@ exports[`directive can use parameters 1`] = `<a href="/foo">Hello John</a>`;
exports[`directive translates text content 1`] = `<a href="/foo">Link text</a>`;

exports[`directive warns about missing key arg 1`] = `<a href="/foo">Fallback text</a>`;

exports[`directive works without fallbacks 1`] = `<a aria-label="Localized aria">Hello John</a>`;
23 changes: 23 additions & 0 deletions test/directive.test.ts
Expand Up @@ -110,4 +110,27 @@ describe('directive', () => {
// Assert
expect(mounted).toMatchSnapshot()
})

it('works without fallbacks', () => {
// Arrange
bundle.addResource(
new FluentResource(ftl`
link = Hello {$name}
.aria-label = Localized aria
`)
)

const component = {
data: () => ({
name: 'John'
}),
template: `<a v-t:link.aria-label="{ name }"></a>`
}

// Act
const mounted = mount(component, options)

// Assert
expect(mounted).toMatchSnapshot()
})
})

0 comments on commit a3581fd

Please sign in to comment.