| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- /* eslint-disable jsdoc/require-jsdoc */
- import {expect} from 'chai';
- import {arrayToString} from './array-to-string.js';
- describe('arrayToString', function () {
- describe('non-array values', function () {
- it('returns a string representation of the given string', function () {
- const res = arrayToString('foo');
- expect(res).to.be.eq('"foo"');
- });
- it('returns a string representation of the given empty string', function () {
- const res = arrayToString('');
- expect(res).to.be.eq('""');
- });
- it('returns a string representation of the given number', function () {
- const res = arrayToString(10);
- expect(res).to.be.eq('10');
- });
- it('returns a string representation of the given zero', function () {
- const res = arrayToString(0);
- expect(res).to.be.eq('0');
- });
- it('returns a string representation of the given NaN', function () {
- const res = arrayToString(NaN);
- expect(res).to.be.eq('NaN');
- });
- it('returns a string representation of the given Infinity', function () {
- const res = arrayToString(Infinity);
- expect(res).to.be.eq('Infinity');
- });
- it('returns a string representation of the given true', function () {
- const res = arrayToString(true);
- expect(res).to.be.eq('true');
- });
- it('returns a string representation of the given false', function () {
- const res = arrayToString(false);
- expect(res).to.be.eq('false');
- });
- it('returns a string representation of the given key-value object', function () {
- const res = arrayToString({foo: 'bar'});
- expect(res).to.be.eq('Object');
- });
- it('returns a string representation of the given object without keys', function () {
- const res = arrayToString({});
- expect(res).to.be.eq('Object');
- });
- it('returns a string representation of the given object without prototype', function () {
- const res = arrayToString(Object.create(null));
- expect(res).to.be.eq('Object');
- });
- it('returns a string representation of the given date instance', function () {
- const res = arrayToString(new Date());
- expect(res).to.be.eq('Date');
- });
- it('returns a string representation of the given map instance', function () {
- const res = arrayToString(new Map());
- expect(res).to.be.eq('Map');
- });
- it('returns a string representation of the given class instance', function () {
- class MyClass {}
- const res = arrayToString(new MyClass());
- expect(res).to.be.eq('MyClass (instance)');
- });
- it('returns a string representation of the given function', function () {
- const res = arrayToString(function () {});
- expect(res).to.be.eq('Function');
- });
- it('returns a string representation of the given anonymous function', function () {
- const res = arrayToString(() => undefined);
- expect(res).to.be.eq('Function');
- });
- it('returns a string representation of the given named function', function () {
- function foo() {}
- const res = arrayToString(foo);
- expect(res).to.be.eq('Function');
- });
- it('returns a string representation of the given anonymous class', function () {
- const res = arrayToString(class {});
- expect(res).to.be.eq('Class');
- });
- it('returns a string representation of the given named class', function () {
- class MyClass {}
- const res = arrayToString(MyClass);
- expect(res).to.be.eq('MyClass');
- });
- it('returns a string representation of the given class constructor', function () {
- class MyClass {}
- const res = arrayToString(MyClass.constructor);
- expect(res).to.be.eq('Function');
- });
- it('returns a string representation of the given symbol', function () {
- const res = arrayToString(Symbol());
- expect(res).to.be.eq('Symbol');
- });
- it('returns a string representation of the given named symbol', function () {
- const res = arrayToString(Symbol('foo'));
- expect(res).to.be.eq('Symbol');
- });
- it('returns a string representation of the given undefined', function () {
- const res = arrayToString(undefined);
- expect(res).to.be.eq('undefined');
- });
- it('returns a string representation of the given null', function () {
- const res = arrayToString(null);
- expect(res).to.be.eq('null');
- });
- });
- describe('array values', function () {
- it('adds a separator between the given elements', function () {
- const res = arrayToString(['foo', 1, true]);
- expect(res).to.be.eq('"foo", 1, true');
- });
- it('returns a string representation of the given empty array', function () {
- const res = arrayToString([]);
- expect(res).to.be.eq('Array');
- });
- it('returns an element representation of the given string', function () {
- const res = arrayToString(['foo']);
- expect(res).to.be.eq('"foo"');
- });
- it('returns an element representation of the given empty string', function () {
- const res = arrayToString(['']);
- expect(res).to.be.eq('""');
- });
- it('returns an element representation of the given number', function () {
- const res = arrayToString([10]);
- expect(res).to.be.eq('10');
- });
- it('returns an element representation of the given zero', function () {
- const res = arrayToString([0]);
- expect(res).to.be.eq('0');
- });
- it('returns an element representation of the given NaN', function () {
- const res = arrayToString([NaN]);
- expect(res).to.be.eq('NaN');
- });
- it('returns an element representation of the given Infinity', function () {
- const res = arrayToString([Infinity]);
- expect(res).to.be.eq('Infinity');
- });
- it('returns an element representation of the given true', function () {
- const res = arrayToString([true]);
- expect(res).to.be.eq('true');
- });
- it('returns an element representation of the given false', function () {
- const res = arrayToString([false]);
- expect(res).to.be.eq('false');
- });
- it('returns an element representation of the given key-value object', function () {
- const res = arrayToString([{foo: 'bar'}]);
- expect(res).to.be.eq('Object');
- });
- it('returns an element representation of the given object without keys', function () {
- const res = arrayToString([{}]);
- expect(res).to.be.eq('Object');
- });
- it('returns an element representation of the given object without prototype', function () {
- const res = arrayToString([Object.create(null)]);
- expect(res).to.be.eq('Object');
- });
- it('returns an element representation of the given date instance', function () {
- const res = arrayToString([new Date()]);
- expect(res).to.be.eq('Date');
- });
- it('returns an element representation of the given map instance', function () {
- const res = arrayToString([new Map()]);
- expect(res).to.be.eq('Map');
- });
- it('returns an element representation of the given class instance', function () {
- class MyClass {}
- const res = arrayToString([new MyClass()]);
- expect(res).to.be.eq('MyClass (instance)');
- });
- it('returns an element representation of the given function', function () {
- const res = arrayToString([function () {}]);
- expect(res).to.be.eq('Function');
- });
- it('returns an element representation of the given anonymous function', function () {
- const res = arrayToString([() => undefined]);
- expect(res).to.be.eq('Function');
- });
- it('returns an element representation of the given named function', function () {
- function foo() {}
- const res = arrayToString([foo]);
- expect(res).to.be.eq('Function');
- });
- it('returns an element representation of the given anonymous class', function () {
- const res = arrayToString([class {}]);
- expect(res).to.be.eq('Class');
- });
- it('returns an element representation of the given named class', function () {
- class MyClass {}
- const res = arrayToString([MyClass]);
- expect(res).to.be.eq('MyClass');
- });
- it('returns an element representation of the given class constructor', function () {
- class MyClass {}
- const res = arrayToString([MyClass.constructor]);
- expect(res).to.be.eq('Function');
- });
- it('returns an element representation of the given symbol', function () {
- const res = arrayToString([Symbol()]);
- expect(res).to.be.eq('Symbol');
- });
- it('returns an element representation of the given named symbol', function () {
- const res = arrayToString([Symbol('foo')]);
- expect(res).to.be.eq('Symbol');
- });
- it('returns an element representation of the given undefined', function () {
- const res = arrayToString([undefined]);
- expect(res).to.be.eq('undefined');
- });
- it('returns an element representation of the given null', function () {
- const res = arrayToString([null]);
- expect(res).to.be.eq('null');
- });
- });
- });
|