Skip to content

Commit

Permalink
test: Add test overriding locales in component options
Browse files Browse the repository at this point in the history
Remove warning for using locale that is not globally available as
I can't see a way to trigger it.
  • Loading branch information
rchl committed Oct 5, 2019
1 parent 214060d commit 3a64fda
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
8 changes: 0 additions & 8 deletions src/helpers/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const {
MODULE_NAME,
STRATEGIES
} = require('./constants')
const { extractComponentOptions } = require('./components')
Expand Down Expand Up @@ -65,13 +64,6 @@ exports.makeRoutes = (baseRoutes, {
let { path } = route
const localizedRoute = { ...route }

// Skip if locale not in module's configuration
if (locales.indexOf(locale) === -1) {
// eslint-disable-next-line no-console
console.warn(`[${MODULE_NAME}] Can't generate localized route for route '${name}' with locale '${locale}' because locale is not in the module's configuration`)
continue
}

// Make localized route name. Name might not exist on parent route if child has same path.
if (name) {
localizedRoute.name = name + routesNameSeparator + locale
Expand Down
6 changes: 5 additions & 1 deletion test/fixture/basic/pages/simple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
</template>

<script>
export default {}
export default {
nuxtI18n: {
locales: ['en', 'fr', 'es'] // locale not defined in global options
}
}
</script>
6 changes: 6 additions & 0 deletions test/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ describe('basic', () => {
expect(response.statusCode).toBe(404)
})

test('route specifies options with non-supported locale', async () => {
await expect(get('/simple')).resolves.toBeDefined()
await expect(get('/fr/simple')).resolves.toBeDefined()
await expect(get('/es/simple')).rejects.toBeDefined()
})

describe('posts', () => {
let html
let title
Expand Down

0 comments on commit 3a64fda

Please sign in to comment.