eugef / node-mocks-http

Mock 'http' objects for testing Express routing functions
Other
747 stars 131 forks source link

Why is baseUrl non-empty? #252

Closed smalllong closed 2 years ago

smalllong commented 2 years ago

In real apps, baseUrl can be empty and path be non-empty when not using router middlewares. But in this mocks, baseUrl is always non-empty when path is not empty. I can not pass an empty baseUrl to override it as it always fallback to path. Why is that?

eugef commented 2 years ago

Hi @smalllong please provide a code example of how are you passing an empty baseUrl

smalllong commented 2 years ago
var createRequest = require('node-mocks-http').createRequest;

console.log(createRequest({
    baseUrl: '',
    path: '/category/request',
    method: 'POST',
  }))
eugef commented 2 years ago

Could you try the following:

const req = createRequest({
    path: '/category/request',
    method: 'POST',
});

req._setBaseUrl('');

// or 

re.baseUrl = ''; 
smalllong commented 2 years ago

That may be working, although I don't think that's the correct solution

github-actions[bot] commented 2 years ago

Stale issue message