-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: implement inheritance with classes (#330)
- Loading branch information
Showing
3 changed files
with
97 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,31 @@ | ||
import { createClassComponent } from 'svelte/legacy' | ||
import { | ||
componentCache, | ||
cleanup, | ||
buildCheckProps, | ||
buildRender, | ||
} from './pure.js' | ||
import { SvelteTestingLibrary } from './pure.js' | ||
|
||
const svelteComponentOptions = [ | ||
'target', | ||
'props', | ||
'events', | ||
'context', | ||
'intro', | ||
'recover', | ||
] | ||
class Svelte5TestingLibrary extends SvelteTestingLibrary { | ||
svelteComponentOptions = [ | ||
'target', | ||
'props', | ||
'events', | ||
'context', | ||
'intro', | ||
'recover', | ||
] | ||
|
||
const checkProps = buildCheckProps(svelteComponentOptions) | ||
|
||
const buildRenderComponent = | ||
({ target, ComponentConstructor }) => | ||
(options) => { | ||
options = { target, ...checkProps(options) } | ||
renderComponent({ target, ComponentConstructor }, options) { | ||
options = { target, ...this.checkProps(options) } | ||
|
||
const component = createClassComponent({ | ||
component: ComponentConstructor, | ||
...options, | ||
}) | ||
|
||
componentCache.add(component) | ||
this.componentCache.add(component) | ||
|
||
return component | ||
} | ||
} | ||
|
||
const render = buildRender(buildRenderComponent) | ||
|
||
/* eslint-disable import/export */ | ||
|
||
import { act, fireEvent } from './pure.js' | ||
const instance = new Svelte5TestingLibrary() | ||
|
||
export { render, cleanup, fireEvent, act } | ||
export const render = instance.render.bind(instance) | ||
export const cleanup = instance.cleanup.bind(instance) |