-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bob Fanger
committed
Jun 17, 2022
1 parent
d3626b9
commit 24e7c17
Showing
12 changed files
with
149 additions
and
36 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
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,13 @@ | ||
<script lang="ts"> | ||
import { createEventDispatcher, onMount } from "svelte"; | ||
const dispatch = createEventDispatcher(); | ||
export let name: string; | ||
onMount(() => { | ||
dispatch("bark", "woof"); | ||
}); | ||
</script> | ||
|
||
<svelte-dog on:click>{name}</svelte-dog> |
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,17 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import * as React from "react"; | ||
import { renderToString } from "react-dom/server"; | ||
import reactifySvelte from "../lib/reactifySvelte"; | ||
import DogSvelte from "./fixtures/Dog.svelte"; | ||
|
||
describe("reactifySvelte", () => { | ||
const Dog = reactifySvelte(DogSvelte); | ||
type ReactProps = React.ComponentProps<typeof Dog>; | ||
it("renders a svelte-wrapper", () => { | ||
const props: ReactProps = { name: "Fido", onBark() {} }; | ||
const html = renderToString(React.createElement(Dog, props)); | ||
expect(html).toMatchInlineSnapshot( | ||
'"<svelte-wrapper style=\\"display:contents\\"></svelte-wrapper>"' | ||
); | ||
}); | ||
}); |
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,17 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import * as React from "react"; | ||
import { renderToString } from "react-dom/server"; | ||
import reactifySvelte from "../lib/reactifySvelte"; | ||
import DogSvelte from "./fixtures/Dog.svelte"; | ||
|
||
describe("reactifySvelte", () => { | ||
const Dog = reactifySvelte(DogSvelte); | ||
type ReactProps = React.ComponentProps<typeof Dog>; | ||
it("renders a svelte-wrapper", () => { | ||
const props: ReactProps = { name: "Fido", onBark() {} }; | ||
const html = renderToString(<Dog/>); | ||
expect(html).toMatchInlineSnapshot( | ||
'"<svelte-wrapper style=\\"display:contents\\"></svelte-wrapper>"' | ||
); | ||
}); | ||
}); |
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,46 @@ | ||
import { noop } from "svelte/internal"; | ||
import { describe, it } from "vitest"; | ||
import type { | ||
EventName, | ||
EventProps, | ||
HandlerName, | ||
OmitEventProps, | ||
SvelteEventHandlers, | ||
} from "../lib/internal/types"; | ||
|
||
const fn = noop as any; | ||
|
||
describe("types", () => { | ||
it("bogus test", () => { | ||
// Types don't fail at runtime, | ||
// Use `tsc --noEmit` to verify that the types are correct. | ||
|
||
type ReactProps = { label: string; onClick(): void }; | ||
|
||
const testEventProps = fn as (_: EventProps<ReactProps>) => void; | ||
testEventProps({ onClick() {} }); | ||
|
||
const testPropsOmitEventProps = fn as ( | ||
_: OmitEventProps<ReactProps> | ||
) => void; | ||
testPropsOmitEventProps({ label: "test" }); | ||
|
||
const testHandlerName = fn as (_: HandlerName<"click">) => void; | ||
testHandlerName("onClick"); | ||
|
||
const testEventName = fn as (_: EventName<"onClick">) => void; | ||
testEventName("click"); | ||
|
||
type SvelteEvents = { | ||
click: MouseEvent; | ||
}; | ||
const testSvelteEventHandlers = fn as ( | ||
_: SvelteEventHandlers<SvelteEvents> | ||
) => void; | ||
testSvelteEventHandlers({ | ||
onClick(event: MouseEvent) { | ||
console.info(event); | ||
}, | ||
}); | ||
}); | ||
}); |
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