1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20import chai from 'chai'; 21import { 22 describe, 23 it 24} from 'mocha'; 25const expect = chai.expect; 26 27import * as utils from '../../runtime/utils/index'; 28 29describe('utils', () => { 30 it('should be an array or object', () => { 31 expect(utils.isObject).to.be.an.instanceof(Function); 32 expect(utils.isObject({})).eql(true); 33 expect(utils.isObject([])).eql(true); 34 expect(utils.isObject('a')).eql(false); 35 expect(utils.isObject(0)).eql(false); 36 expect(utils.isObject(true)).eql(false); 37 expect(utils.isObject(null)).eql(false); 38 expect(utils.isObject(undefined)).eql(false); 39 expect(utils.isObject(function() {})).eql(false); 40 expect(utils.isObject(/\w*/)).eql(true); 41 expect(utils.isObject(new Date())).eql(true); 42 }); 43 44 it('should be an real object', () => { 45 expect(utils.isPlainObject).to.be.an.instanceof(Function); 46 expect(utils.isPlainObject({})).eql(true); 47 expect(utils.isPlainObject([])).eql(false); 48 expect(utils.isPlainObject('a')).eql(false); 49 expect(utils.isPlainObject(0)).eql(false); 50 expect(utils.isPlainObject(true)).eql(false); 51 expect(utils.isPlainObject(null)).eql(false); 52 expect(utils.isPlainObject(undefined)).eql(false); 53 expect(utils.isPlainObject(function() {})).eql(false); 54 expect(utils.isPlainObject(/\w*/)).eql(false); 55 expect(utils.isPlainObject(new Date())).eql(false); 56 }); 57 58 it('has own property', () => { 59 expect(utils.hasOwn).to.be.an.instanceof(Function); 60 function Point() { 61 this.x = 0; 62 } 63 Point.prototype.y = 1; 64 const p = new Point(); 65 expect(p.x).eql(0); 66 expect(p.y).eql(1); 67 expect(utils.hasOwn(p, 'x')).eql(true); 68 expect(utils.hasOwn(p, 'y')).eql(false); 69 }); 70 71 it('own property is empty or not', () => { 72 expect(utils.isEmpty).to.be.an.instanceof(Function); 73 expect(utils.isEmpty({})).eql(true); 74 expect(utils.isEmpty([])).eql(true); 75 expect(utils.isEmpty('a')).eql(true); 76 expect(utils.isEmpty(0)).eql(true); 77 expect(utils.isEmpty(true)).eql(true); 78 expect(utils.isEmpty(null)).eql(true); 79 expect(utils.isEmpty(undefined)).eql(true); 80 expect(utils.isEmpty(function() {})).eql(true); 81 expect(utils.isEmpty(/\w*/)).eql(true); 82 expect(utils.isEmpty(new Date())).eql(true); 83 function Point() { 84 this.x = 0; 85 } 86 const p = new Point(); 87 expect(p.x).eql(0); 88 expect(utils.isEmpty(p)).eql(false); 89 Point.prototype.y = 1; 90 expect(p.y).eql(1); 91 expect(utils.isEmpty(p)).eql(false); 92 }); 93 94 it('is null or undefined', () => { 95 expect(utils.isNull).to.be.an.instanceof(Function); 96 expect(utils.isNull({})).eql(false); 97 expect(utils.isNull([])).eql(false); 98 expect(utils.isNull('a')).eql(false); 99 expect(utils.isNull(0)).eql(false); 100 expect(utils.isNull(true)).eql(false); 101 expect(utils.isNull(null)).eql(true); 102 expect(utils.isNull(undefined)).eql(true); 103 expect(utils.isNull(function() {})).eql(false); 104 expect(utils.isNull(/\w*/)).eql(false); 105 expect(utils.isNull(new Date())).eql(false); 106 }); 107}); 108