Skip to content
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

Provide request headers in response function #218

Open
chaptergy opened this issue Oct 10, 2024 · 0 comments · May be fixed by #219
Open

Provide request headers in response function #218

chaptergy opened this issue Oct 10, 2024 · 0 comments · May be fixed by #219

Comments

@chaptergy
Copy link

Sometimes the mock response should depend on a header send with the request, for example if the Accept or Accept-Language header was set. This would make request handlers like this possible:

story.parameters = {
    mockData: [
        url: 'https://jsonplaceholder.typicode.com/todos/1',
        method: 'GET',
        status: 200,
        response: (request) => {
            const { headers } = request;

            if (headers.get('Accept-Language') === 'fr-FR') {
                return {
                    data: 'Données en français',
                };
            }
            return { data: 'Default data' };
        },
    ],
};
@chaptergy chaptergy linked a pull request Oct 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant