123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import {
- stringify,
- isDefined,
- isUndefined,
- isEmpty,
- isRegExp,
- } from 'handsontable/helpers/mixed';
- describe('Mixed helper', () => {
- describe('stringify', () => {
- it('should convert properly `null` to `string`', () => {
- var toConvert = null;
- expect(stringify(toConvert)).toBe('');
- });
- it('should convert properly `boolean` to `string`', () => {
- var toConvert = true;
- expect(stringify(toConvert)).toBe('true');
- });
- it('should convert properly `number` to `string`', () => {
- var toConvert = 1;
- expect(stringify(toConvert)).toBe('1');
- });
- it('should convert properly `string` to `string`', () => {
- var toConvert = '2';
- expect(stringify(toConvert)).toBe('2');
- });
- it('should convert properly `object` to `string`', () => {
- var toConvert = {id: null};
- expect(stringify(toConvert)).toBe('[object Object]');
- });
- it('should convert properly `array` to `string`', () => {
- var toConvert = ['One', 'Two', 3];
- expect(stringify(toConvert)).toBe('One,Two,3');
- });
- it('should convert properly `RegExp` to `string`', () => {
- var toConvert = /^\d$/;
- expect(stringify(toConvert)).toBe('/^\\d$/');
- });
- it('should convert properly `function` to `string`', () => {
- var toConvert = function() {};
- expect(stringify(toConvert)).toMatch(/function/i);
- });
- it('should convert properly `undefined` to `string`', () => {
- var toConvert;
- expect(stringify(toConvert)).toBe('');
- });
- });
- describe('isDefined', () => {
- it('should return true when a variable is defined', () => {
- var toCheck = [];
- expect(isDefined(toCheck)).toBeTruthy();
- });
- it('should return false when a variable is not defined', () => {
- var toCheck;
- expect(isDefined(toCheck)).toBeFalsy();
- });
- });
- describe('isUndefined', () => {
- it('should check if a variable is defined', () => {
- var toCheck;
- expect(isUndefined(toCheck)).toBeTruthy();
- });
- it('should return false when a variable is not defined', () => {
- var toCheck = [];
- expect(isUndefined(toCheck)).toBeFalsy();
- });
- });
- describe('isEmpty', () => {
- it('should check if a variable is null, empty string or undefined', () => {
- expect(isEmpty(undefined)).toBeTruthy();
- expect(isEmpty('')).toBeTruthy();
- expect(isEmpty(null)).toBeTruthy();
- });
- it('should return false when a variable isn\'t null, empty string or undefined', () => {
- expect(isEmpty(NaN)).toBeFalsy();
- expect(isEmpty(0)).toBeFalsy();
- expect(isEmpty('a')).toBeFalsy();
- expect(isEmpty([])).toBeFalsy();
- expect(isEmpty({})).toBeFalsy();
- });
- });
- describe('isRegExp', () => {
- it('should check if a variable is a valid regular expression', () => {
- expect(isRegExp(undefined)).toBeFalsy();
- expect(isRegExp('')).toBeFalsy();
- expect(isRegExp(null)).toBeFalsy();
- expect(isRegExp(0)).toBeFalsy();
- expect(isRegExp(1)).toBeFalsy();
- expect(isRegExp('foo')).toBeFalsy();
- expect(isRegExp({a: /\d+/})).toBeFalsy();
- expect(isRegExp(/\d+/)).toBeTruthy();
- expect(isRegExp(new RegExp('d+'))).toBeTruthy();
- });
- });
- });
|