Skip to content

Commit

Permalink
Add String passthrough to handle edge-cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Coulbourne committed Aug 23, 2017
1 parent f3613f6 commit 7835ca2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/js/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down Expand Up @@ -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();
};
Expand Down
25 changes: 25 additions & 0 deletions tests/js/test.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7835ca2

Please sign in to comment.