create-cookie-string.spec.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import {expect} from 'chai';
  2. import {format} from '@e22m4u/js-format';
  3. import {createCookieString} from './create-cookie-string.js';
  4. describe('createCookieString', function () {
  5. it('requires the first parameter to be an object', function () {
  6. const throwable = v => () => createCookieString(v);
  7. const error = v =>
  8. format(
  9. 'The first parameter of "createCookieString" should be ' +
  10. 'an Object, but %s was given.',
  11. v,
  12. );
  13. expect(throwable('str')).to.throw(error('"str"'));
  14. expect(throwable('')).to.throw(error('""'));
  15. expect(throwable(10)).to.throw(error('10'));
  16. expect(throwable(0)).to.throw(error('0'));
  17. expect(throwable(true)).to.throw(error('true'));
  18. expect(throwable(false)).to.throw(error('false'));
  19. expect(throwable(null)).to.throw(error('null'));
  20. expect(throwable([])).to.throw(error('Array'));
  21. expect(throwable(undefined)).to.throw(error('undefined'));
  22. throwable({key: 'value'})();
  23. throwable({})();
  24. });
  25. it('returns an empty string if no keys', function () {
  26. expect(createCookieString({})).to.be.eq('');
  27. });
  28. it('returns a cookies string from a given object', function () {
  29. const data = {foo: 'bar', baz: 'quz'};
  30. const result = createCookieString(data);
  31. expect(result).to.be.eq('foo=bar; baz=quz;');
  32. });
  33. });