mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.57k stars 1.07k forks source link

new Date() only returns the date when the mock-server is up. #967

Closed aaron-pacora closed 2 years ago

aaron-pacora commented 3 years ago

Hello; This is my code, when I assign the new Date () to return the current date and time, it does not change the value, it remains static no matter how many times it consumes.

This value only changes when I restart the mock-server.

I am using docker;

mockServerClient(HOST, PORT).mockAnyResponse(
{
        'httpRequest': {
            'method': 'GET',
            'path': 'claims/get-claims/123456'
        },
        'httpResponse': {
            'statusCode': 200,
            'headers': [
                {"name": "Content-Type", "values": ["application/json; charset=utf-8"]},
                {"name": "Access-Control-Allow-Headers", "values": ["Content-Type"]}
            ],
            'body': JSON.stringify({
'registered_date': new Date()
})
        },
        'times': {
            'unlimited': true
        }
    }
));
jamesdbloom commented 2 years ago

That's because the date function is evaluated client side not inside MockServer so your sending a static value to MockServer.

I hope that makes sense?

Closing ticket as this is not an big in MockServer.