Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: mock properties of classes/functions (fix #1523)
Previously classes weren't mocked properly because their prototypes were not being copied, so they lost all their methods. This commit rewrites the automocker to properly handle: - Functions with properties (namely classes) - Circular objects (also to handle classes, thanks JavaScript) With these changes classes can now be properly automocked! This fixes #1523.
- Loading branch information
1 parent
9ef62b5
commit a465428
Showing
3 changed files
with
152 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { mockedA } from './mockedA' | ||
|
||
export class MockedC { | ||
public value: number | ||
|
||
constructor() { | ||
this.value = 42 | ||
} | ||
|
||
public doSomething() { | ||
return mockedA() | ||
} | ||
|
||
get getSetProp(): number { | ||
return 123 | ||
} | ||
|
||
set getSetProp(_val: number) {} | ||
} | ||
|
||
export async function asyncFunc(): Promise<string> { | ||
await new Promise<void>(resolve => resolve()) | ||
return '1234' | ||
} |
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