-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stubs): Allow to stub directives
* this adds stubbing directives functionality to @vue/test-utils
- Loading branch information
Showing
11 changed files
with
372 additions
and
65 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Component } from 'vue' | ||
|
||
// Stubbing occurs when in vnode transformer we're swapping | ||
// component vnode type due to stubbing either component | ||
// or directive on component | ||
|
||
// In order to be able to find components we need to track pairs | ||
// stub --> original component | ||
|
||
// Having this as global might feel unsafe at first point | ||
// One can assume that sharing stub map across mounts might | ||
// lead to false matches, however our vnode mappers always | ||
// produce new nodeTypes for each mount even if you're reusing | ||
// same stub, so we're safe and do not need to pass these stubs | ||
// for each mount operation | ||
const stubs: WeakMap<Component, Component> = new WeakMap() | ||
|
||
export function registerStub({ | ||
source, | ||
stub | ||
}: { | ||
source: Component | ||
stub: Component | ||
}) { | ||
stubs.set(stub, source) | ||
} | ||
|
||
export function getOriginalComponentFromStub( | ||
stub: Component | ||
): Component | undefined { | ||
return stubs.get(stub) | ||
} |
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
Oops, something went wrong.