forked from vue-leaflet/vue-leaflet
-
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.
Add basic tests for LControlAttribution
- Loading branch information
Showing
7 changed files
with
571 additions
and
41 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
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
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,86 @@ | ||
import { flushPromises, shallowMount } from "@vue/test-utils"; | ||
import "leaflet"; | ||
import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
||
import LControlAttribution from "@src/components/LControlAttribution.vue"; | ||
import { | ||
RegisterControlInjection, | ||
UseGlobalLeafletInjection, | ||
} from "@src/types/injectionKeys"; | ||
|
||
describe("LControlAttribution", () => { | ||
const mockRegisterControl = vi.fn(); | ||
const getWrapper = async () => { | ||
const wrapper = shallowMount(LControlAttribution, { | ||
propsData: { | ||
position: "topright", | ||
prefix: "Hello there", | ||
}, | ||
global: { | ||
provide: { | ||
[UseGlobalLeafletInjection as symbol]: true, | ||
[RegisterControlInjection as symbol]: mockRegisterControl, | ||
}, | ||
}, | ||
}); | ||
await flushPromises(); | ||
|
||
return wrapper; | ||
}; | ||
|
||
beforeEach(() => { | ||
mockRegisterControl.mockReset(); | ||
}); | ||
|
||
it("emits a ready event", async () => { | ||
const wrapper = await getWrapper(); | ||
|
||
expect(wrapper.emitted("ready")).to.have.length(1); | ||
}); | ||
|
||
it("creates a Leaflet object with expected properties", async () => { | ||
const wrapper = await getWrapper(); | ||
|
||
expect(wrapper.vm.leafletObject).to.exist; | ||
const leafletObject = wrapper.vm.leafletObject!; | ||
expect(leafletObject!.options.prefix).to.equal("Hello there"); | ||
expect(leafletObject?.options.position).to.equal("topright"); | ||
}); | ||
|
||
it("registers its Leaflet object", async () => { | ||
const wrapper = await getWrapper(); | ||
|
||
expect(mockRegisterControl).toHaveBeenCalledTimes(1); | ||
expect(mockRegisterControl).toHaveBeenCalledWith({ | ||
leafletObject: wrapper.vm.leafletObject, | ||
}); | ||
}); | ||
|
||
it("sets the prefix value", async () => { | ||
const wrapper = await getWrapper(); | ||
expect(wrapper.vm.leafletObject?.options.prefix); | ||
|
||
wrapper.setProps({ prefix: "new prefix" }); | ||
|
||
await flushPromises(); | ||
expect(wrapper.vm.leafletObject?.options.prefix).to.equal("new prefix"); | ||
}); | ||
|
||
it("sets a new position value", async () => { | ||
const wrapper = await getWrapper(); | ||
|
||
wrapper.setProps({ position: "bottomleft" }); | ||
|
||
await flushPromises(); | ||
expect(wrapper.vm.leafletObject?.options.position).to.equal("bottomleft"); | ||
}); | ||
|
||
it("removes itself from the map on unmount", async () => { | ||
const wrapper = await getWrapper(); | ||
const removeSpy = vi.spyOn(wrapper.vm.leafletObject!, "remove"); | ||
|
||
wrapper.unmount(); | ||
|
||
expect(removeSpy).toBeCalledTimes(1); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/// <reference types="vitest" /> | ||
import { mergeConfig } from "vite"; | ||
import { defineConfig } from "vitest/config"; | ||
|
||
import viteConfig from "./vite.config"; | ||
|
||
export default mergeConfig( | ||
viteConfig, | ||
defineConfig({ | ||
test: { | ||
exclude: ["node_modules"], | ||
globals: true, | ||
environment: "jsdom", | ||
}, | ||
}) | ||
); |
Oops, something went wrong.