Closed
Description
What is the problem this feature will solve?
I want to mock an value of object in my unit tests.
{ value: {β¦}, writable: true, enumerable: true, configurable: true }
The MockTracker
class can mock method, getter and setter, but not value.
I'm currently using sinon
, but I'd like to replace it with a native Node.js mock.
sinon.stub(browser.contextMenus, "ContextType").value({ LINK: "link", PAGE: "page" });
That would also replace this kind of case:
const originalContextType = browser.contextMenus.ContextType;
try {
browser.contextMenus.ContextType = { LINK: "link", PAGE: "page" };
// Do test.
} finally {
browser.contextMenus.ContextType = originalContextType;
}
What is the feature you are proposing to solve the problem?
mock.value(object, valueName, value)
object
<Object>
The object whose value is being mocked.valueName
<string>
|<symbol>
The identifier of the value onobject
to mock. Ifobject[valueName]
is not a value, an error is thrown.value
<any>
A value used as the mock value for object[valueName].
What alternatives have you considered?
The mock.getter()
function can mock a value.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Awaiting Triage