<NME> cookie-spec.js
<BEF> import Cookies from 'js-cookie';
import { cookie } from '../../../../lib/utils/cookie';

describe('Keen.utils.cookie', function() {

  beforeEach(() => {
    this.cookie = cookie('keen-test-cookie');
  });

  afterEach(() => {
    this.cookie.expire();
  });

  describe('constructor', () => {

    it('should return a constructed object', function() {
      expect().isObject(this.cookie);
    });

    it('should have internal properties', function() {
      expect().isObject(this.cookie.data);
      expect().isObject(this.cookie.config.options);
      expect().isString(this.cookie.config.key);
      expect().equal(this.cookie.config.key, 'keen-test-cookie');
    });

    it('should have prototype methods', function() {
      expect().isFunction(this.cookie.get);
      expect().isFunction(this.cookie.set);
      expect().isFunction(this.cookie.expire);
    });

  });

  describe('.get', () => {

    it('should return a simple string for pre-existing non-json data', () => {
      Cookies.set('keen-test-cookie', 'some thing that is not json');
      expect().deepEqual(this.cookie.get(), 'some thing that is not json');
    });

    it('should return an empty object when no key name is provided and no data has been stored', () => {
      expect().deepEqual(this.cookie.get(), {});
    });

    it('should return stored key', () => {
      this.cookie.set('mocha-test-getter', 123);
      expect().deepEqual(this.cookie.get('mocha-test-getter'), 123);
    });

    it('should return null when requesting an unstored key', () => {
      expect().isNull(this.cookie.get('mocha-null'));
    });

  });

  describe('.set', () => {

    it('should set a string value', () => {
      this.cookie.set('library', 'keen-tracking.js');
      expect().equal(this.cookie.get('library'), 'keen-tracking.js');
    });

    it('should set a numeric value', () => {
      this.cookie.set('number', 123);
      expect().equal(this.cookie.get('number'), 123);
    });

    it('should set an array value', () => {
      this.cookie.set('array', ['1', 2, false]);
      expect().deepEqual(this.cookie.get('array'), ['1', 2, false]);
    });

    it('should set an object value to a key', () => {
      this.cookie.set('object', { object: true });
      expect().deepEqual(this.cookie.get('object'), { object: true });
    });

    it('should set an object of key:value pairs', () => {
      this.cookie.set({
        library: 'keen-tracking.js',
        number: 123,
        array: ['1', 2, false],
        object: { object: true }
      });
      const data = this.cookie.get();
      expect().equal(data.library, 'keen-tracking.js');
      expect().equal(data.number, 123);
      expect().deepEqual(data.array, ['1', 2, false]);
      expect().deepEqual(data.object, { object: true });
    });

  });

  describe('.expire', () => {

    it('should expire the cookie', () => {
      this.cookie.set('library', 'keen-tracking.js');
      this.cookie.expire();
      expect().deepEqual(this.cookie.get(), {});
    });

  });

  describe('.options', () => {

    it('should set options for cookies', () => {
      this.cookie.options({ secure: false });
      expect().equal(this.cookie.config.options.secure, false);
    });

    it('should get options for cookies', () => {
      this.cookie.options({ secure: false });
      expect().deepEqual(this.cookie.options(), { secure: false });
    });

  });

  describe('.enabled', () => {

    it('should return a boolean value', () => {
      expect().isBoolean(this.cookie.enabled());
    });

  });

});

<MSG> fix tests for cookie util

<DFF> @@ -1,33 +1,33 @@
 import Cookies from 'js-cookie';
 import { cookie } from '../../../../lib/utils/cookie';
 
-describe('Keen.utils.cookie', function() {
+describe('Keen.utils.cookie', () => {
+  let cookie1;
 
   beforeEach(() => {
-    this.cookie = cookie('keen-test-cookie');
+    cookie1 = cookie('keen-test-cookie');
   });
 
   afterEach(() => {
-    this.cookie.expire();
+    cookie1.expire();
   });
 
   describe('constructor', () => {
 
-    it('should return a constructed object', function() {
-      expect().isObject(this.cookie);
+    it('should return a constructed object', () => {
+      expect(cookie1).toBeInstanceOf(Object);
     });
 
-    it('should have internal properties', function() {
-      expect().isObject(this.cookie.data);
-      expect().isObject(this.cookie.config.options);
-      expect().isString(this.cookie.config.key);
-      expect().equal(this.cookie.config.key, 'keen-test-cookie');
+    it('should have internal properties', () => {
+      expect(cookie1.data).toBeInstanceOf(Object);
+      expect(cookie1.config.options).toBeInstanceOf(Object);
+      expect(cookie1.config.key).toBe('keen-test-cookie');
     });
 
-    it('should have prototype methods', function() {
-      expect().isFunction(this.cookie.get);
-      expect().isFunction(this.cookie.set);
-      expect().isFunction(this.cookie.expire);
+    it('should have prototype methods', () => {
+      expect(cookie1.get).toBeInstanceOf(Function);
+      expect(cookie1.set).toBeInstanceOf(Function);
+      expect(cookie1.expire).toBeInstanceOf(Function);
     });
 
   });
@@ -36,20 +36,20 @@ describe('Keen.utils.cookie', function() {
 
     it('should return a simple string for pre-existing non-json data', () => {
       Cookies.set('keen-test-cookie', 'some thing that is not json');
-      expect().deepEqual(this.cookie.get(), 'some thing that is not json');
+      expect(cookie1.get()).toEqual('some thing that is not json');
     });
 
     it('should return an empty object when no key name is provided and no data has been stored', () => {
-      expect().deepEqual(this.cookie.get(), {});
+      expect(cookie1.get()).toEqual({});
     });
 
     it('should return stored key', () => {
-      this.cookie.set('mocha-test-getter', 123);
-      expect().deepEqual(this.cookie.get('mocha-test-getter'), 123);
+      cookie1.set('mocha-test-getter', 123);
+      expect(cookie1.get('mocha-test-getter')).toEqual(123);
     });
 
     it('should return null when requesting an unstored key', () => {
-      expect().isNull(this.cookie.get('mocha-null'));
+      expect(cookie1.get('mocha-null')).toBe(null);
     });
 
   });
@@ -57,37 +57,42 @@ describe('Keen.utils.cookie', function() {
   describe('.set', () => {
 
     it('should set a string value', () => {
-      this.cookie.set('library', 'keen-tracking.js');
-      expect().equal(this.cookie.get('library'), 'keen-tracking.js');
+      cookie1.set('library', 'keen-tracking.js');
+      expect(cookie1.get('library')).toBe('keen-tracking.js');
     });
 
     it('should set a numeric value', () => {
-      this.cookie.set('number', 123);
-      expect().equal(this.cookie.get('number'), 123);
+      cookie1.set('number', 123);
+      expect(cookie1.get('number')).toBe(123);
     });
 
     it('should set an array value', () => {
-      this.cookie.set('array', ['1', 2, false]);
-      expect().deepEqual(this.cookie.get('array'), ['1', 2, false]);
+      cookie1.set('array', ['1', 2, false]);
+      expect(cookie1.get('array')).toEqual(['1', 2, false]);
     });
 
     it('should set an object value to a key', () => {
-      this.cookie.set('object', { object: true });
-      expect().deepEqual(this.cookie.get('object'), { object: true });
+      cookie1.set('object', { object: true });
+      expect(cookie1.get('object')).toEqual({ object: true });
     });
 
     it('should set an object of key:value pairs', () => {
-      this.cookie.set({
+      cookie1.set({
         library: 'keen-tracking.js',
         number: 123,
         array: ['1', 2, false],
         object: { object: true }
       });
-      const data = this.cookie.get();
-      expect().equal(data.library, 'keen-tracking.js');
-      expect().equal(data.number, 123);
-      expect().deepEqual(data.array, ['1', 2, false]);
-      expect().deepEqual(data.object, { object: true });
+      const data = cookie1.get();
+      expect(data.library).toEqual('keen-tracking.js');
+      expect(data.number).toEqual(123);
+      expect(data.array).toEqual(['1', 2, false]);
+      expect(data.object).toEqual({ object: true });
+    });
+
+    it('should set an object value to a key when extended options passed', () => {
+      cookie1.set('object', { object: true }, {});
+      expect(cookie1.get('object')).toEqual({ object: true });
     });
 
   });
@@ -95,9 +100,9 @@ describe('Keen.utils.cookie', function() {
   describe('.expire', () => {
 
     it('should expire the cookie', () => {
-      this.cookie.set('library', 'keen-tracking.js');
-      this.cookie.expire();
-      expect().deepEqual(this.cookie.get(), {});
+      cookie1.set('library', 'keen-tracking.js');
+      cookie1.expire();
+      expect(cookie1.get()).toEqual({});
     });
 
   });
@@ -105,13 +110,13 @@ describe('Keen.utils.cookie', function() {
   describe('.options', () => {
 
     it('should set options for cookies', () => {
-      this.cookie.options({ secure: false });
-      expect().equal(this.cookie.config.options.secure, false);
+      cookie1.options({ secure: false });
+      expect(cookie1.config.options.secure).toEqual(false);
     });
 
     it('should get options for cookies', () => {
-      this.cookie.options({ secure: false });
-      expect().deepEqual(this.cookie.options(), { secure: false });
+      cookie1.options({ secure: false });
+      expect(cookie1.options()).toEqual({ secure: false });
     });
 
   });
@@ -119,7 +124,7 @@ describe('Keen.utils.cookie', function() {
   describe('.enabled', () => {
 
     it('should return a boolean value', () => {
-      expect().isBoolean(this.cookie.enabled());
+      expect(cookie1.enabled()).toBe(true);
     });
 
   });

{'addition_count': 46, 'commit_subject': 'fix tests for cookie util', 'deletion_count': 41, 'file_extension': '.js', 'lang': 'js', 'license': 'mit', 'repo_name': 'keen/keen-tracking.js'}