From 7835ca20c717600b4df606a47b485b61d686d521 Mon Sep 17 00:00:00 2001 From: Daniel Coulbourne Date: Wed, 23 Aug 2017 07:40:44 -0400 Subject: [PATCH] Add String passthrough to handle edge-cases. --- src/js/route.js | 11 +++++++++++ tests/js/test.route.js | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/js/route.js b/src/js/route.js index 92caaa2b..c6bcbd31 100644 --- a/src/js/route.js +++ b/src/js/route.js @@ -5,8 +5,14 @@ var Router = function(name, params, absolute) { this.absolute = absolute === undefined ? true : absolute; this.domain = this.constructDomain(); this.url = namedRoutes[this.name].uri.replace(/^\//, ''); + + String.call(this); }; + +Router.prototype = Object.create(String.prototype); +Router.prototype.constructor = Router; + Router.prototype.normalizeParams = function(params) { if (params === undefined) return {}; @@ -85,6 +91,11 @@ Router.prototype.toString = function() { return this.return; }; +Router.prototype.valueOf = function() { + this.parse(); + return this.return; +}; + Router.prototype.parse = function() { this.return = this.constructUrl() + this.constructQuery(); }; diff --git a/tests/js/test.route.js b/tests/js/test.route.js index c5c9b2fe..8e3b791a 100644 --- a/tests/js/test.route.js +++ b/tests/js/test.route.js @@ -142,6 +142,31 @@ describe('route()', function() { .get(route('posts.show', 1)) .then(function(response) { assert.equal(200, response.status) + }).catch(function(error) { + throw error; + }); + + moxios.uninstall() + }); + + it('Should make an axios call when a route() and params are passed', function() { + moxios.install(); + + moxios.stubRequest('http://myapp.dev/posts/1', { + status: 200, + responseText: "Worked!" + }); + + axios.get(route('posts.index'), { + page: 2, + params: { thing: 'thing'} + }) + .then(function(response) { + assert.equal(200, response.status) + + }).catch(function(error) { + console.log(error); + assert.equal(true, false); }); moxios.uninstall()