1/* 2 * Copyright (c) 2021-2024 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 assertNull from './assertNull'; 17import assertClose from './assertClose'; 18import assertContain from './assertContain'; 19import assertLess from './assertLess'; 20import assertLarger from './assertLarger'; 21import assertFail from './assertFail'; 22import assertUndefined from './assertUndefined'; 23import assertFalse from './assertFalse'; 24import assertInstanceOf from './assertInstanceOf'; 25import assertThrowError from './assertThrowError'; 26import assertLargerOrEqual from './assertLargerOrEqual'; 27import assertLessOrEqual from './assertLessOrEqual'; 28import assertNaN from './assertNaN'; 29import assertNegUnlimited from './assertNegUnlimited'; 30import assertPosUnlimited from './assertPosUnlimited'; 31import assertDeepEquals from './deepEquals/assertDeepEquals'; 32import assertPromiseIsPending from './assertPromiseIsPending'; 33import assertPromiseIsRejected from './assertPromiseIsRejected'; 34import assertPromiseIsRejectedWith from './assertPromiseIsRejectedWith'; 35import assertPromiseIsRejectedWithError from './assertPromiseIsRejectedWithError'; 36import assertPromiseIsResolved from './assertPromiseIsResolved'; 37import assertPromiseIsResolvedWith from './assertPromiseIsResolvedWith'; 38class ExpectExtend { 39 constructor(attr) { 40 this.id = attr.id; 41 this.matchers = {}; 42 } 43 44 extendsMatchers() { 45 this.matchers.assertNull = assertNull; 46 this.matchers.assertClose = assertClose; 47 this.matchers.assertContain = assertContain; 48 this.matchers.assertLess = assertLess; 49 this.matchers.assertLarger = assertLarger; 50 this.matchers.assertFail = assertFail; 51 this.matchers.assertUndefined = assertUndefined; 52 this.matchers.assertFalse = assertFalse; 53 this.matchers.assertInstanceOf = assertInstanceOf; 54 this.matchers.assertThrowError = assertThrowError; 55 this.matchers.assertLargerOrEqual = assertLargerOrEqual; 56 this.matchers.assertLessOrEqual = assertLessOrEqual; 57 this.matchers.assertNaN = assertNaN; 58 this.matchers.assertNegUnlimited = assertNegUnlimited; 59 this.matchers.assertPosUnlimited = assertPosUnlimited; 60 this.matchers.assertDeepEquals = assertDeepEquals; 61 this.matchers.assertPromiseIsPending = assertPromiseIsPending; 62 this.matchers.assertPromiseIsRejected = assertPromiseIsRejected; 63 this.matchers.assertPromiseIsRejectedWith = assertPromiseIsRejectedWith; 64 this.matchers.assertPromiseIsRejectedWithError = assertPromiseIsRejectedWithError; 65 this.matchers.assertPromiseIsResolved = assertPromiseIsResolved; 66 this.matchers.assertPromiseIsResolvedWith = assertPromiseIsResolvedWith; 67 } 68 69 init(coreContext) { 70 this.coreContext = coreContext; 71 this.extendsMatchers(); 72 const expectService = this.coreContext.getDefaultService('expect'); 73 expectService.addMatchers(this.matchers); 74 } 75 76 apis() { 77 return { 78 'expect': function (actualValue) { 79 return this.coreContext.getDefaultService('expect').expect(actualValue); 80 } 81 }; 82 } 83} 84 85export default ExpectExtend; 86