-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test case for string type #64
Conversation
In what context are you using the route() method? We are testing it with an axios call to ensure that the object is cast to a string. I can't think of a use case where it wouldn't be cast to a string so I'd love to hear what you're doing to see if there's a way to make this work for you. |
You can see that my test failed because
You can check the gifs. Laravel 5.4.33, Laravel Mix, Chrome 60 stable, Mac OS Seirra |
I think the culprit is this method, var Router = function(name, params, absolute) {
this.name = name;
this.urlParams = this.normalizeParams(params);
this.queryParams = this.normalizeParams(params);
this.absolute = absolute === undefined ? true : absolute;
this.domain = this.constructDomain();
this.url = namedRoutes[this.name].uri.replace(/^\//, '');
// should return something here ?
}; This is not returning anything. |
The route() method DOES return an object, but when that object is cast to a string it should return the route as it previously did. The reason the other tests pass is because we it is being cast to a string before being compared to the expected strings. the I don't want to assert that |
I think you are talking about Now i got your point now, it is working fine. |
Good point! I'll do that in the morning 😴 |
I found this to be a problem when passing the route as a prop to a Vue component, which validated for String type. |
Any chance you could show me your code so I can see if I can work around it? @alepeino |
@DanielCoulbourne <!-- form.blade.php -->
<my-form-component :action="route('form-action')"></my-form-component> <!-- form.vue -->
<template>
<form :action="action">
<!-- form inputs -->
</form>
</template>
<script>
export default {
name: 'my-form-component',
props: {
action: {
type: String,
required: true
},
},
}
</script> |
👆 that, exactly |
Okidoke. I'll try to hack on that use case and see if I can fix it for ya. In the meantime you should be able to use v0.3.0 with no problem I think. |
@DanielCoulbourne
although of course it would be nicer to avoid the need to convert explicitly. |
yup! I'll figure this out. Why are you type-checking for String, if you don't mind me asking? Seems like there are a lot of cases where you could accidentally trip that wire. |
Sure, I don't really need the type-check. But what if I don't own the component? |
No I totally get that. It just seems like a kind of strict type-check. So far anywhere that you explicitly check that Ideally you would check that something behaves like a string, since that's what really matters. If you WERE going to typecheck strings directly (instead of checking that it has the functionality you want) if I am checking that something is type |
Cool, I didn't know about that difference in behavior. So, it looks like in this case (depending on a 3rd party Vue component that you can't change, which does this kind of strict type checking) explicit |
Yep. I actually just opened an issue over there to see if we can get that changed: vuejs/vue#6447 |
Hey everyone! Evan merged the change to Vue so this should be good to go now! |
Awesome |
In my current project, I'm using ziggy to create routes to be posted via axios. It gave me quite a time trying to figure out why my XSRF token was not being set. Since
This was my calling code: var store_uri = this.owner.type === 'user'
? route('api.user.projects.store')
: route('api.team.projects.store', {team_slug: this.owner.slug});
var form = this.form;
var owner = this.owner;
axios.post(store_uri, form)... I added an explicit
Without this, the XSRF TOKEN was not being set correctly and I was getting "Session expired" when trying to use Spark's It would be great to better understand how The flexibility of being able to get a |
Yeah so I've been Ruminating on this quite a bit. I may create a Alternatively, I may do something like allowing users to set a config variable to determine whether they want to use primitive wrappers or not. |
Yep, +1 on @simensen's point about XSRF — I'm experiencing this too. Obviously, it's frustrating to now have to go and stick Making the return type configurable seems sensible, @DanielCoulbourne. I guess we'd want some way to override the config on a per-case basis? E.g. if ziggy was configured to always return a raw URL string from |
@Harrisonbro just a note that |
Version 0.4.0 is no longer working for me.
I rolled back to 0.3.0.
When i run
route("valid-route")
in console, it returnsobject
rather url (string).So i am adding a test case for future proofing.
The
route()
method is expected to return string types if everything goes well.Something is wrong with existing test cases. Don't know how they get passed.
May be choose a different assertion library.