Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
e187ea06
Commit
e187ea06
authored
May 16, 2023
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused `mockBaseClass` helper
The code that used to use this has been refactored to avoid inheritance.
parent
51b74441
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
33 deletions
+0
-33
mock-base.js
src/test-util/mock-base.js
+0
-33
No files found.
src/test-util/mock-base.js
deleted
100644 → 0
View file @
51b74441
/**
* Mock the base class of a derived class.
*
* In unit tests for a derived class it may be useful to mock the base class
* so that the tests only depend on the interface of the base class and not
* its implementation.
*
* This cannot be done using `$imports.$mock` because the links between the
* derived and base class are set once when the derived class is initially
* evaluated.
*
* Although it is possible to mock a base class using this function, using
* composition over inheritance generally makes mocking easier.
*
* @param {object} derivedClass - The derived class constructor to mock
* @param {object} mockBase - The new mock class
* @return {() => void} A function that un-mocks the base class
*/
export
function
mockBaseClass
(
derivedClass
,
mockBase
)
{
const
originalBase
=
derivedClass
.
__proto__
;
// Modify the base class reference used by `super` expressions.
derivedClass
.
__proto__
=
mockBase
;
// Modify the prototype chain used by instances of the derived class to find
// methods or properties defined on the base class.
derivedClass
.
prototype
.
__proto__
=
mockBase
.
prototype
;
return
()
=>
{
derivedClass
.
__proto__
=
originalBase
;
derivedClass
.
prototype
.
__proto__
=
originalBase
.
prototype
;
};
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment