|
| 1 | +/** |
| 2 | + * Copyright (c) 2002-2017 "Neo Technology,"," |
| 3 | + * Network Engine for Objects in Lund AB [http://neotechnology.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +const util = require('../../lib/v1/internal/util.js'); |
| 21 | + |
| 22 | +describe('util', () => { |
| 23 | + |
| 24 | + it('should check empty objects', () => { |
| 25 | + expect(util.isEmptyObjectOrNull(null)).toBeTruthy(); |
| 26 | + expect(util.isEmptyObjectOrNull({})).toBeTruthy(); |
| 27 | + expect(util.isEmptyObjectOrNull([])).toBeTruthy(); |
| 28 | + |
| 29 | + const func = () => { |
| 30 | + return 42; |
| 31 | + }; |
| 32 | + expect(util.isEmptyObjectOrNull(func)).toBeTruthy(); |
| 33 | + func.foo = 'bar'; |
| 34 | + expect(util.isEmptyObjectOrNull(func)).toBeFalsy(); |
| 35 | + |
| 36 | + expect(util.isEmptyObjectOrNull()).toBeFalsy(); |
| 37 | + expect(util.isEmptyObjectOrNull(undefined)).toBeFalsy(); |
| 38 | + expect(util.isEmptyObjectOrNull(0)).toBeFalsy(); |
| 39 | + expect(util.isEmptyObjectOrNull('')).toBeFalsy(); |
| 40 | + expect(util.isEmptyObjectOrNull('abc')).toBeFalsy(); |
| 41 | + expect(util.isEmptyObjectOrNull({foo: 'bar'})).toBeFalsy(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should check strings', () => { |
| 45 | + verifyValidString(''); |
| 46 | + verifyValidString(new String('foo')); |
| 47 | + verifyValidString(String('foo')); |
| 48 | + verifyValidString("hi!"); |
| 49 | + |
| 50 | + verifyInvalidString({}); |
| 51 | + verifyInvalidString({foo: 1}); |
| 52 | + verifyInvalidString([]); |
| 53 | + verifyInvalidString(['1']); |
| 54 | + verifyInvalidString([1, '2']); |
| 55 | + verifyInvalidString(console.log); |
| 56 | + }); |
| 57 | + |
| 58 | + function verifyValidString(str) { |
| 59 | + expect(util.assertString(str, 'Test string')).toBe(str); |
| 60 | + } |
| 61 | + |
| 62 | + function verifyInvalidString(str) { |
| 63 | + expect(() => util.assertString(str, 'Test string')).toThrowError(TypeError); |
| 64 | + } |
| 65 | + |
| 66 | +}); |
0 commit comments