diff options
author | 2023-06-24 02:24:05 -0400 | |
---|---|---|
committer | 2023-06-23 23:24:05 -0700 | |
commit | ceec1afec2bb187fecef0f5006dfe27ee3e1a9a6 (patch) | |
tree | 75ce279ace8d4cd783b42927ea872089093725b9 /src/bun.js/bindings/JSMockFunction.cpp | |
parent | 5ae8e5d773c6b57fe166681ffa9cdc153f69427b (diff) | |
download | bun-ceec1afec2bb187fecef0f5006dfe27ee3e1a9a6.tar.gz bun-ceec1afec2bb187fecef0f5006dfe27ee3e1a9a6.tar.zst bun-ceec1afec2bb187fecef0f5006dfe27ee3e1a9a6.zip |
Add vi.spyOn and clean up some mock function binding calls (#3376)
* Add vi.spyOn and clean up some binding calls
* add vi.restoreAllMocks
* remove junk file
---------
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Diffstat (limited to 'src/bun.js/bindings/JSMockFunction.cpp')
-rw-r--r-- | src/bun.js/bindings/JSMockFunction.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/bun.js/bindings/JSMockFunction.cpp b/src/bun.js/bindings/JSMockFunction.cpp index b7c2659b4..fbfcf0c9e 100644 --- a/src/bun.js/bindings/JSMockFunction.cpp +++ b/src/bun.js/bindings/JSMockFunction.cpp @@ -391,6 +391,7 @@ void JSMockFunction::visitChildrenImpl(JSCell* cell, Visitor& visitor) visitor.append(fn->instances); visitor.append(fn->returnValues); visitor.append(fn->invocationCallOrder); + visitor.append(fn->spyOriginal); fn->mock.visit(visitor); } DEFINE_VISIT_CHILDREN(JSMockFunction); @@ -526,13 +527,13 @@ extern "C" void JSMock__resetSpies(Zig::GlobalObject* globalObject) globalObject->mockModule.activeSpies.clear(); } -extern "C" EncodedJSValue jsFunctionResetSpies(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe) +extern "C" EncodedJSValue JSMock__jsRestoreAllMocks(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe) { JSMock__resetSpies(jsCast<Zig::GlobalObject*>(globalObject)); return JSValue::encode(jsUndefined()); } -extern "C" EncodedJSValue JSMock__spyOn(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callframe) +extern "C" EncodedJSValue JSMock__jsSpyOn(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callframe) { auto& vm = lexicalGlobalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); @@ -963,7 +964,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsMockFunctionGetter_protoImpl, (JSC::JSGlobalObject * return JSValue::encode(jsUndefined()); } -JSC_DEFINE_HOST_FUNCTION(jsMockFunctionConstructor, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callframe)) +extern "C" EncodedJSValue JSMock__jsMockFn(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callframe) { auto& vm = lexicalGlobalObject->vm(); auto* globalObject = jsCast<Zig::GlobalObject*>(lexicalGlobalObject); @@ -997,11 +998,6 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionConstructor, (JSC::JSGlobalObject * lexic return JSValue::encode(thisObject); } -extern "C" EncodedJSValue JSMockFunction__createObject(Zig::GlobalObject* globalObject) -{ - auto& vm = globalObject->vm(); - return JSValue::encode(JSC::JSFunction::create(vm, globalObject, 0, "mock"_s, jsMockFunctionConstructor, ImplementationVisibility::Public)); -} extern "C" EncodedJSValue JSMockFunction__getCalls(EncodedJSValue encodedValue) { JSValue value = JSValue::decode(encodedValue); |