From 115086904961ddf3b74161f4794afeccc5d59773 Mon Sep 17 00:00:00 2001 From: Craig Paul <=> Date: Tue, 27 Aug 2019 15:48:46 -0600 Subject: [PATCH] Adds test for setting an accept-language header --- src/__mocks__/axios.ts | 8 +++++++- src/index.test.ts | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/__mocks__/axios.ts b/src/__mocks__/axios.ts index cad0c2e..35d4fec 100644 --- a/src/__mocks__/axios.ts +++ b/src/__mocks__/axios.ts @@ -1,5 +1,11 @@ export default { - create: jest.fn(() => Promise.resolve({})), + create: jest.fn(() => ({ + defaults: { + headers: { + common: {}, + }, + }, + })), delete: jest.fn(() => Promise.resolve({ data: {} })), get: jest.fn(() => Promise.resolve({ data: {} })), patch: jest.fn(() => Promise.resolve({ data: {} })), diff --git a/src/index.test.ts b/src/index.test.ts index 172d345..e25eb5b 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -76,3 +76,15 @@ it('can access the forms resource', async () => { expect(instance.forms()).toBeInstanceOf(Form.prototype.constructor); }); + +it('can set an accepted language header', async () => { + const instance = new OpenApi('admin'); + + instance.locale('es'); + + const object = JSON.parse(JSON.stringify(instance)); + + expect(object.client.defaults.headers.common).toMatchObject({ + 'Accept-Language': 'es', + }); +});