1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { MockKit } from "./MockKit.js"; 17 18class ExtendInterface { 19 20 private mocker: MockKit 21 private params: any 22 23 constructor(mocker: MockKit) { 24 this.mocker = mocker; 25 } 26 27 stub() { 28 this.params = arguments; 29 return this; 30 } 31 32 stubMockedCall(returnInfo: any) { 33 this.mocker.stubApply(this, this.params, returnInfo); 34 } 35 36 afterReturn(value: any) { 37 this.stubMockedCall(function () { 38 return value; 39 }); 40 } 41 42 afterReturnNothing() { 43 this.stubMockedCall(function () { 44 return undefined; 45 }); 46 } 47 48 afterAction(action: Function) { 49 this.stubMockedCall(action); 50 } 51 52 afterThrow(msg: string) { 53 this.stubMockedCall(function () { 54 throw msg; 55 }); 56 } 57 58 clear(obj?: any) { 59 this.mocker.clear(obj); 60 } 61} 62 63export default ExtendInterface;