forked from huntabyte/bits-ui
-
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.
Internal Refactor & Add Tests (huntabyte#149)
- Loading branch information
Showing
89 changed files
with
5,360 additions
and
355 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,5 @@ | ||
--- | ||
"bits-ui": patch | ||
--- | ||
|
||
Remove `ToggleInput` & fix bugs |
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,89 @@ | ||
// setupTest.ts | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
import matchers from "@testing-library/jest-dom/matchers"; | ||
import { expect, vi } from "vitest"; | ||
import type { Navigation, Page } from "@sveltejs/kit"; | ||
import { readable } from "svelte/store"; | ||
import * as environment from "$app/environment"; | ||
import * as navigation from "$app/navigation"; | ||
import * as stores from "$app/stores"; | ||
import { toHaveNoViolations } from "jest-axe"; | ||
import { configure } from "@testing-library/dom"; | ||
|
||
// Add custom jest matchers | ||
expect.extend(matchers); | ||
|
||
expect.extend(toHaveNoViolations as never); | ||
|
||
configure({ | ||
asyncUtilTimeout: 1500 | ||
}); | ||
|
||
// Mock SvelteKit runtime module $app/environment | ||
vi.mock("$app/environment", (): typeof environment => ({ | ||
browser: false, | ||
dev: true, | ||
building: false, | ||
version: "any" | ||
})); | ||
|
||
// Mock SvelteKit runtime module $app/navigation | ||
vi.mock("$app/navigation", (): typeof navigation => ({ | ||
afterNavigate: () => {}, | ||
beforeNavigate: () => {}, | ||
disableScrollHandling: () => {}, | ||
goto: () => Promise.resolve(), | ||
invalidate: () => Promise.resolve(), | ||
invalidateAll: () => Promise.resolve(), | ||
preloadData: () => Promise.resolve(), | ||
preloadCode: () => Promise.resolve(), | ||
onNavigate: () => {} | ||
})); | ||
|
||
// Mock SvelteKit runtime module $app/stores | ||
vi.mock("$app/stores", (): typeof stores => { | ||
const getStores: typeof stores.getStores = () => { | ||
const navigating = readable<Navigation | null>(null); | ||
const page = readable<Page>({ | ||
url: new URL("http://localhost"), | ||
params: {}, | ||
route: { | ||
id: null | ||
}, | ||
status: 200, | ||
error: null, | ||
data: {}, | ||
form: undefined | ||
}); | ||
const updated = { subscribe: readable(false).subscribe, check: async () => false }; | ||
|
||
return { navigating, page, updated }; | ||
}; | ||
|
||
const page: typeof stores.page = { | ||
subscribe(fn) { | ||
return getStores().page.subscribe(fn); | ||
} | ||
}; | ||
const navigating: typeof stores.navigating = { | ||
subscribe(fn) { | ||
return getStores().navigating.subscribe(fn); | ||
} | ||
}; | ||
const updated: typeof stores.updated = { | ||
subscribe(fn) { | ||
return getStores().updated.subscribe(fn); | ||
}, | ||
check: async () => false | ||
}; | ||
|
||
return { | ||
getStores, | ||
navigating, | ||
page, | ||
updated | ||
}; | ||
}); | ||
|
||
global.ResizeObserver = require("resize-observer-polyfill"); | ||
Element.prototype.scrollIntoView = () => {}; |
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
Oops, something went wrong.