• 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
16/**
17 * the actualValue contain expect
18 * @param actualValue
19 * @param expect: the expect value
20 * @example
21 *         expect(array).toBeContain(anItem)
22 *         expect(String).toBeContain(subString)
23 * @returns {{pass: boolean, message: string}}
24 */
25function assertContain (actualValue, expect) {
26  let result = false
27  if (Object.prototype.toString.call(actualValue).indexOf('Array')) {
28    for (let i in actualValue) {
29      if (actualValue[i] == expect[0]) {
30        result = true
31      }
32    }
33  }
34  let type = Object.prototype.toString.call(actualValue)
35  if (type === '[object String]') {
36    result = actualValue.indexOf(expect[0]) >= 0
37  }
38  return {
39    pass: result,
40    message: 'except false, ' + actualValue + ' do not have  ' + expect[0]
41  }
42}
43
44export default assertContain
45