• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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 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';
26
27class ExpectExtend {
28    constructor(attr) {
29        this.id = attr.id;
30        this.matchers = {};
31    }
32
33    extendsMatchers() {
34        this.matchers.assertNull = assertNull;
35        this.matchers.assertClose = assertClose;
36        this.matchers.assertContain = assertContain;
37        this.matchers.assertLess = assertLess;
38        this.matchers.assertLarger = assertLarger;
39        this.matchers.assertFail = assertFail;
40        this.matchers.assertUndefined = assertUndefined;
41        this.matchers.assertFalse = assertFalse;
42        this.matchers.assertInstanceOf = assertInstanceOf;
43        this.matchers.assertThrowError = assertThrowError;
44    }
45
46    init(coreContext) {
47        this.coreContext = coreContext;
48        this.extendsMatchers();
49        const expectService = this.coreContext.getDefaultService('expect');
50        expectService.addMatchers(this.matchers);
51    }
52
53    apis() {
54        return {
55            'expect': function (actualValue) {
56                return this.coreContext.getDefaultService('expect').expect(actualValue);
57            }
58        };
59    }
60}
61
62export default ExpectExtend;
63