forked from aws-amplify/maplibre-gl-js-amplify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add unit test for createMap (aws-amplify#162)
* Add unit test for createMap * Remove unnecessary jest env header * Polyfill Worker for jsdom env
- Loading branch information
Showing
5 changed files
with
120 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Amplify } from "@aws-amplify/core"; | ||
import { Geo } from "@aws-amplify/geo"; | ||
import type { AmazonLocationServiceMapStyle } from "@aws-amplify/geo"; | ||
|
||
import { createMap } from "../src/AmplifyMapLibreRequest"; | ||
|
||
jest.mock("@aws-amplify/geo"); | ||
|
||
describe('createMap', () => { | ||
Amplify.Auth = {}; | ||
Amplify.Auth.currentCredentials = jest.fn().mockImplementation(() => { | ||
return { | ||
accessKeyId: "accessKeyId", | ||
sessionToken: "sessionTokenId", | ||
secretAccessKey: "secretAccessKey", | ||
identityId: "identityId", | ||
authenticated: true, | ||
expiration: new Date(), | ||
}; | ||
}); | ||
|
||
beforeEach(() => { | ||
(Geo.getDefaultMap as jest.Mock).mockClear(); | ||
}); | ||
|
||
test("createMap returns a map object", async () => { | ||
(Geo.getDefaultMap as jest.Mock).mockReturnValueOnce({ | ||
mapName: "map1ff111f1-staging", | ||
region: "us-east-1", | ||
style: "VectorEsriStreets" | ||
} as AmazonLocationServiceMapStyle); | ||
|
||
const el = document.createElement("div"); | ||
el.setAttribute("id", "map"); | ||
document.body.appendChild(el); | ||
|
||
const map = await createMap({ | ||
container: "map", | ||
center: [-123.1187, 49.2819], | ||
zoom: 11, | ||
}); | ||
|
||
expect(map).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
testMatch: ["<rootDir>/__tests__/**/*.ts"], | ||
transform: { | ||
"/node_modules/mapbox-gl-draw-circle.+\\.js$": "babel-jest", // mapbox-gl-draw-circle needs to be transpiled to cjs | ||
".+\\.(svg|css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": | ||
"jest-transform-stub", | ||
}, | ||
moduleNameMapper: { | ||
"^.+.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": | ||
"jest-transform-stub", | ||
}, | ||
transformIgnorePatterns: ["/node_modules/(?!mapbox-gl-draw-circle).+\\.js$"], | ||
projects: [ | ||
{ | ||
moduleNameMapper: { | ||
"^.+.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": | ||
"jest-transform-stub", | ||
}, | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
testMatch: ["<rootDir>/__tests__/**/*.test.ts"], | ||
transform: { | ||
"/node_modules/mapbox-gl-draw-circle.+\\.js$": "babel-jest", // mapbox-gl-draw-circle needs to be transpiled to cjs | ||
".+\\.(svg|css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": | ||
"jest-transform-stub", | ||
}, | ||
transformIgnorePatterns: ["/node_modules/(?!mapbox-gl-draw-circle).+\\.js$"], | ||
}, | ||
{ | ||
preset: "ts-jest", | ||
setupFiles: ["./jest.setup.dom.ts", "jest-webgl-canvas-mock", "jsdom-worker-fix"], // workarounds for jsdom and node env conflicts | ||
testEnvironment: "jsdom", | ||
testMatch: ["<rootDir>/__tests__/**/*.test.dom.ts"], | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* This is a workaround to the problem of the jsdom library not supporting | ||
* URL.createObjectURL. See https://github.com/jsdom/jsdom/issues/1721. | ||
*/ | ||
if (typeof window.URL.createObjectURL === 'undefined') { | ||
window.URL.createObjectURL = jest.fn(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters