fix(jest): add stub for errActions to prevent unhandled promise rejections #6365 (#6495)

Co-authored-by: Theo Markovic <theodore.markovic@svenskaspel.se>
This commit is contained in:
Theo Markovic
2020-10-15 02:07:49 +02:00
committed by GitHub
parent 3905fadfbe
commit 537ad6d6bf

View File

@@ -57,7 +57,7 @@ describe("auth plugin - actions", () => {
}, },
"http://specs/authorize" "http://specs/authorize"
], ],
].forEach(([{oas3, server, effectiveServer, scheme, host, url}, expectedFetchUrl]) => { ].forEach(([{ oas3, server, effectiveServer, scheme, host, url }, expectedFetchUrl]) => {
it("should resolve authorization endpoint against the server URL", () => { it("should resolve authorization endpoint against the server URL", () => {
// Given // Given
@@ -72,6 +72,9 @@ describe("auth plugin - actions", () => {
authSelectors: { authSelectors: {
getConfigs: () => ({}) getConfigs: () => ({})
}, },
errActions: {
newAuthErr: () => ({})
},
oas3Selectors: { oas3Selectors: {
selectedServer: () => server, selectedServer: () => server,
serverEffectiveValue: () => effectiveServer || server serverEffectiveValue: () => effectiveServer || server
@@ -89,7 +92,7 @@ describe("auth plugin - actions", () => {
// Then // Then
expect(system.fn.fetch.mock.calls.length).toEqual(1) expect(system.fn.fetch.mock.calls.length).toEqual(1)
expect(system.fn.fetch.mock.calls[0][0]).toEqual(expect.objectContaining({url: expectedFetchUrl})) expect(system.fn.fetch.mock.calls[0][0]).toEqual(expect.objectContaining({ url: expectedFetchUrl }))
}) })
}) })
@@ -111,6 +114,9 @@ describe("auth plugin - actions", () => {
} }
}) })
}, },
errActions: {
newAuthErr: () => ({})
},
specSelectors: { specSelectors: {
isOAS3: () => false, isOAS3: () => false,
operationScheme: () => "https", operationScheme: () => "https",
@@ -139,6 +145,9 @@ describe("auth plugin - actions", () => {
fn: { fn: {
fetch: jest.fn().mockImplementation(() => Promise.resolve()) fetch: jest.fn().mockImplementation(() => Promise.resolve())
}, },
errActions: {
newAuthErr: () => ({})
},
getConfigs: () => ({}), getConfigs: () => ({}),
authSelectors: { authSelectors: {
getConfigs: () => ({ getConfigs: () => ({
@@ -167,7 +176,7 @@ describe("auth plugin - actions", () => {
}) })
}) })
describe("tokenRequest", function() { describe("tokenRequest", function () {
it("should send the code verifier when set", () => { it("should send the code verifier when set", () => {
const data = { const data = {
auth: { auth: {
@@ -203,8 +212,8 @@ describe("auth plugin - actions", () => {
const system = { const system = {
getConfigs: () => ({}), getConfigs: () => ({}),
authActions: { authActions: {
authorize: jest.fn(()=>{}), authorize: jest.fn(() => { }),
persistAuthorizationIfNeeded: jest.fn(()=>{}) persistAuthorizationIfNeeded: jest.fn(() => { })
} }
} }
@@ -226,8 +235,8 @@ describe("auth plugin - actions", () => {
const system = { const system = {
getConfigs: () => ({}), getConfigs: () => ({}),
authActions: { authActions: {
authorizeOauth2: jest.fn(()=>{}), authorizeOauth2: jest.fn(() => { }),
persistAuthorizationIfNeeded: jest.fn(()=>{}) persistAuthorizationIfNeeded: jest.fn(() => { })
} }
} }
@@ -249,8 +258,8 @@ describe("auth plugin - actions", () => {
const system = { const system = {
getConfigs: () => ({}), getConfigs: () => ({}),
authActions: { authActions: {
logout: jest.fn(()=>{}), logout: jest.fn(() => { }),
persistAuthorizationIfNeeded: jest.fn(()=>{}) persistAuthorizationIfNeeded: jest.fn(() => { })
} }
} }
@@ -275,7 +284,7 @@ describe("auth plugin - actions", () => {
persistAuthorization: false persistAuthorization: false
}), }),
authSelectors: { authSelectors: {
authorized: jest.fn(()=>{}) authorized: jest.fn(() => { })
} }
} }
@@ -294,8 +303,11 @@ describe("auth plugin - actions", () => {
getConfigs: () => ({ getConfigs: () => ({
persistAuthorization: true persistAuthorization: true
}), }),
errActions: {
newAuthErr: () => ({})
},
authSelectors: { authSelectors: {
authorized: jest.fn(()=>Map(data)) authorized: jest.fn(() => Map(data))
} }
} }
jest.spyOn(Object.getPrototypeOf(window.localStorage), "setItem") jest.spyOn(Object.getPrototypeOf(window.localStorage), "setItem")