jameslnewell / xhr-mock

Utility for mocking XMLHttpRequest.
196 stars 48 forks source link

Just a note on HTTP method capitalisation (not really an issue...) #28

Closed zz-james closed 7 years ago

zz-james commented 7 years ago

I just made a silly error which took me all morning to find.

Browsers handle GET and POST case-insensitively but XHR-mock does not. https://stackoverflow.com/questions/7790576/what-are-http-method-capitalization-best-practices

-- in line 90 of index.js for xhr-mock

post: function(url, fn) { return this.mock('POST', url, fn); } this string is compared to the method sent from the code being tested, if your code sends lower case it will fail, (not sure if you want to str.toUpperCase() or just let it fail)

Obviously I think it's best practice to always capitalise http methods but this was a slip up which was not obvious (since the code worked but the test failed)

Hope it's useful to someone.

James

jameslnewell commented 7 years ago

Thanks for the issue! I think this is already fixed in my v2 branch. Once a get some more time I'll get it released.