From 1a4822e38d83e4869f9eecf1185277a3b1008a9e Mon Sep 17 00:00:00 2001 From: Alexandre Chopin Date: Wed, 11 Jan 2017 15:03:26 +0100 Subject: [PATCH] add new test for dynamic routes --- test/dynamic-routes.test.js | 45 ++++++++++++------- test/fixtures/dynamic-routes/pages/index.vue | 0 test/fixtures/dynamic-routes/pages/posts.vue | 0 .../dynamic-routes/pages/posts/_id.vue | 0 .../dynamic-routes/pages/test/songs/_id.vue | 0 5 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 test/fixtures/dynamic-routes/pages/index.vue create mode 100644 test/fixtures/dynamic-routes/pages/posts.vue create mode 100644 test/fixtures/dynamic-routes/pages/posts/_id.vue create mode 100644 test/fixtures/dynamic-routes/pages/test/songs/_id.vue diff --git a/test/dynamic-routes.test.js b/test/dynamic-routes.test.js index 3e9e47b87f..ef6ae53fd6 100644 --- a/test/dynamic-routes.test.js +++ b/test/dynamic-routes.test.js @@ -24,28 +24,41 @@ test('Check .nuxt/router.js', t => { .replace('routes: [', '[') .replace(/ _[0-9A-z]+,/g, ' "",') let routes = eval('( ' + routerFile + ')') // eslint-disable-line no-eval + // pages/index.vue + t.is(routes[0].path, '/') + t.is(routes[0].name, 'index') // pages/test/index.vue - t.is(routes[0].path, '/test') - t.is(routes[0].name, 'test') + t.is(routes[1].path, '/test') + t.is(routes[1].name, 'test') + // pages/posts.vue + t.is(routes[2].path, '/posts') + t.is(routes[2].name, 'posts') + t.is(routes[2].children.length, 1) + // pages/posts/_id.vue + t.is(routes[2].children[0].path, ':id?') + t.is(routes[2].children[0].name, 'posts-id') // pages/parent.vue - t.is(routes[1].path, '/parent') - t.falsy(routes[1].name) // parent route has no name + t.is(routes[3].path, '/parent') + t.falsy(routes[3].name) // parent route has no name // pages/parent/*.vue - t.is(routes[1].children.length, 3) // parent has 3 children - t.deepEqual(routes[1].children.map((r) => r.path), ['', 'teub', 'child']) - t.deepEqual(routes[1].children.map((r) => r.name), ['parent', 'parent-teub', 'parent-child']) + t.is(routes[3].children.length, 3) // parent has 3 children + t.deepEqual(routes[3].children.map((r) => r.path), ['', 'teub', 'child']) + t.deepEqual(routes[3].children.map((r) => r.name), ['parent', 'parent-teub', 'parent-child']) // pages/test/users.vue - t.is(routes[2].path, '/test/users') - t.falsy(routes[2].name) // parent route has no name + t.is(routes[4].path, '/test/users') + t.falsy(routes[4].name) // parent route has no name // pages/test/users/*.vue - t.is(routes[2].children.length, 3) // parent has 3 children - t.deepEqual(routes[2].children.map((r) => r.path), ['', ':id', ':index/teub']) - t.deepEqual(routes[2].children.map((r) => r.name), ['test-users', 'test-users-id', 'test-users-index-teub']) + t.is(routes[4].children.length, 3) // parent has 3 children + t.deepEqual(routes[4].children.map((r) => r.path), ['', ':id', ':index/teub']) + t.deepEqual(routes[4].children.map((r) => r.name), ['test-users', 'test-users-id', 'test-users-index-teub']) + // pages/test/songs/_id.vue + t.is(routes[5].path, '/test/songs/:id?') + t.is(routes[5].name, 'test-songs-id') // pages/_slug.vue - t.is(routes[3].path, '/:slug?') - t.is(routes[3].name, 'slug') + t.is(routes[6].path, '/:slug') + t.is(routes[6].name, 'slug') // pages/_key/_id.vue - t.is(routes[4].path, '/:key?/:id?') - t.is(routes[4].name, 'key-id') + t.is(routes[7].path, '/:key/:id?') + t.is(routes[7].name, 'key-id') }) }) diff --git a/test/fixtures/dynamic-routes/pages/index.vue b/test/fixtures/dynamic-routes/pages/index.vue new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/dynamic-routes/pages/posts.vue b/test/fixtures/dynamic-routes/pages/posts.vue new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/dynamic-routes/pages/posts/_id.vue b/test/fixtures/dynamic-routes/pages/posts/_id.vue new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/dynamic-routes/pages/test/songs/_id.vue b/test/fixtures/dynamic-routes/pages/test/songs/_id.vue new file mode 100644 index 0000000000..e69de29bb2