<commit_before>﻿describe('UNIT TESTS', function () {
    var mockDocument;

    beforeEach(function () {
        mockDocument = {};
        Cookies._document = mockDocument;
        Cookies._cachedDocumentCookie = '';
    });

    describe('Cookies(key)', function () {
        it('returns `Cookies.get(key)`', function () {
            var key = 'key';
            var value = 'value';
            
            spyOn(Cookies, 'get').andReturn(value);
            
            expect(Cookies(key)).toEqual(value);
            expect(Cookies.get).toHaveBeenCalledWith(key);
        });
    });

    describe('Cookies(key, value[, options])', function () {
        var key = 'key';
        var value = 'value';
        var options = undefined;
        
        it('calls `Cookies.set(key, value, options)`', function () {
            spyOn(Cookies, 'set');
            Cookies(key, value, options);
            
            expect(Cookies.set).toHaveBeenCalledWith(key, value, options);
        });
        
        it('returns `Cookies`', function () {
            expect(Cookies(key, value, options)).toEqual(Cookies);
        });
    });

    describe('Cookies.defaults', function () {
        it('has a defined `path` value of "/"', function () {
            expect(Cookies.defaults.path).toEqual('/');
        });
        
        it('has an undefined `domain` value', function () {
            expect(Cookies.defaults.domain).toBeUndefined();
        });
        
        it('has an undefined `expires` value', function () {
            expect(Cookies.defaults.expires).toBeUndefined();
        });
        
        it('has an undefined `secure` value', function () {
            expect(Cookies.defaults.secure).toBeUndefined();
        });
    });

    describe('Cookies.get(key)', function () {
        var key;
        
        beforeEach(function () {
            key = 'key';
            mockDocument.cookie = 'key=value';
        });
        
        it('returns `undefined` when `key` is undefined', function () {
            key = undefined;
            expect(Cookies.get(key)).toBeUndefined();
        });
        
        it('returns `undefined` for a cookie key that does not exist', function () {
            key = 'undefined';
            expect(Cookies.get(key)).toBeUndefined();
        });
        
        it('calls `Cookies._renewCache()` when `document.cookie` does not equal `Cookies._cachedDocumentCookie`', function () {
            Cookies._cachedDocumentCookie = undefined;
            
            spyOn(Cookies, '_renewCache');
            Cookies.get(key);
            
            expect(Cookies._renewCache).toHaveBeenCalled();
        });
        
        it('does not call `Cookies._renewCache()` when `document.cookie` equals `Cookies._cachedDocumentCookie`', function () {
            Cookies._cachedDocumentCookie = mockDocument.cookie;
            
            spyOn(Cookies, '_renewCache');
            Cookies.get('key');
            
            expect(Cookies._renewCache).not.toHaveBeenCalled();
        });
        
        it('returns the value of `Cookies._cache[key]`', function () {
            Cookies._cachedDocumentCookie = mockDocument.cookie; // Prevents cache from renewing
            Cookies._cache = { key: 'value' };
            
            expect(Cookies.get(key)).toEqual(Cookies._cache[key]);
        });
    });

    describe('Cookies.set(key, value[, options])', function () {
        var key, value, options;
        var originalDefaults = Cookies.defaults;
        
        beforeEach(function () {
            key = 'key';
            value = 'value';
            options = undefined;
            
            Cookies.defaults = {
                path: '/cookies',
                domain: 'www.scotthamper.com',
                expires: '01/01/2013 GMT',
                secure: false
            };
        });
        
        afterEach(function () {
            Cookies.defaults = originalDefaults;
        });
        
        it('returns the `Cookies` object', function () {
            expect(Cookies.set(key, value, options)).toEqual(Cookies);
        });
        
        it('calls `Cookies._getExtendedOptions(options)`', function () {
            options = { path: '/' };
            
            spyOn(Cookies, '_getExtendedOptions').andCallThrough();
            Cookies.set(key, value, options);
            
            expect(Cookies._getExtendedOptions).toHaveBeenCalledWith(options);
        });
        
        it('calls `Cookies._getExpiresDate(options.expires)`', function () {
            options = { expires: '01/01/2013' };
            
            spyOn(Cookies, '_getExpiresDate').andCallThrough();
            Cookies.set(key, value, options);
            
            expect(Cookies._getExpiresDate).toHaveBeenCalledWith(options.expires);
        });
        
        it('calls `Cookies._getExpiresDate(-1)` when value is `undefined`', function () {
            options = { expires: '01/01/2013' };
            
            spyOn(Cookies, '_getExpiresDate').andCallThrough();
            Cookies.set(key, undefined, options);
            
            expect(Cookies._getExpiresDate).toHaveBeenCalledWith(-1);
        });
        
        it('calls `Cookies._generateCookieString(key, value, options)` with extended options and options.expires as a Date instance', function () {
            var extendedOptionsWithExpiresDate = {
                path: Cookies.defaults.path,
                domain: Cookies.defaults.domain,
                expires: new Date(Cookies.defaults.expires),
                secure: Cookies.defaults.secure
            };<commit_msg>Added an expectation to a Cookies.set unit test<commit_after>﻿describe('UNIT TESTS', function () {
    var mockDocument;

    beforeEach(function () {
        mockDocument = {};
        Cookies._document = mockDocument;
        Cookies._cachedDocumentCookie = '';
    });

    describe('Cookies(key)', function () {
        it('returns `Cookies.get(key)`', function () {
            var key = 'key';
            var value = 'value';
            
            spyOn(Cookies, 'get').andReturn(value);
            
            expect(Cookies(key)).toEqual(value);
            expect(Cookies.get).toHaveBeenCalledWith(key);
        });
    });

    describe('Cookies(key, value[, options])', function () {
        var key = 'key';
        var value = 'value';
        var options = undefined;
        
        it('calls `Cookies.set(key, value, options)`', function () {
            spyOn(Cookies, 'set');
            Cookies(key, value, options);
            
            expect(Cookies.set).toHaveBeenCalledWith(key, value, options);
        });
        
        it('returns `Cookies`', function () {
            expect(Cookies(key, value, options)).toEqual(Cookies);
        });
    });

    describe('Cookies.defaults', function () {
        it('has a defined `path` value of "/"', function () {
            expect(Cookies.defaults.path).toEqual('/');
        });
        
        it('has an undefined `domain` value', function () {
            expect(Cookies.defaults.domain).toBeUndefined();
        });
        
        it('has an undefined `expires` value', function () {
            expect(Cookies.defaults.expires).toBeUndefined();
        });
        
        it('has an undefined `secure` value', function () {
            expect(Cookies.defaults.secure).toBeUndefined();
        });
    });

    describe('Cookies.get(key)', function () {
        var key;
        
        beforeEach(function () {
            key = 'key';
            mockDocument.cookie = 'key=value';
        });
        
        it('returns `undefined` when `key` is undefined', function () {
            key = undefined;
            expect(Cookies.get(key)).toBeUndefined();
        });
        
        it('returns `undefined` for a cookie key that does not exist', function () {
            key = 'undefined';
            expect(Cookies.get(key)).toBeUndefined();
        });
        
        it('calls `Cookies._renewCache()` when `document.cookie` does not equal `Cookies._cachedDocumentCookie`', function () {
            Cookies._cachedDocumentCookie = undefined;
            
            spyOn(Cookies, '_renewCache');
            Cookies.get(key);
            
            expect(Cookies._renewCache).toHaveBeenCalled();
        });
        
        it('does not call `Cookies._renewCache()` when `document.cookie` equals `Cookies._cachedDocumentCookie`', function () {
            Cookies._cachedDocumentCookie = mockDocument.cookie;
            
            spyOn(Cookies, '_renewCache');
            Cookies.get('key');
            
            expect(Cookies._renewCache).not.toHaveBeenCalled();
        });
        
        it('returns the value of `Cookies._cache[key]`', function () {
            Cookies._cachedDocumentCookie = mockDocument.cookie; // Prevents cache from renewing
            Cookies._cache = { key: 'value' };
            
            expect(Cookies.get(key)).toEqual(Cookies._cache[key]);
        });
    });

    describe('Cookies.set(key, value[, options])', function () {
        var key, value, options;
        var originalDefaults = Cookies.defaults;
        
        beforeEach(function () {
            key = 'key';
            value = 'value';
            options = undefined;
            
            Cookies.defaults = {
                path: '/cookies',
                domain: 'www.scotthamper.com',
                expires: '01/01/2013 GMT',
                secure: false
            };
        });
        
        afterEach(function () {
            Cookies.defaults = originalDefaults;
        });
        
        it('returns the `Cookies` object', function () {
            expect(Cookies.set(key, value, options)).toEqual(Cookies);
        });
        
        it('calls `Cookies._getExtendedOptions(options)`', function () {
            options = { path: '/' };
            
            spyOn(Cookies, '_getExtendedOptions').andCallThrough();
            Cookies.set(key, value, options);
            
            expect(Cookies._getExtendedOptions).toHaveBeenCalledWith(options);
        });
        
        it('calls `Cookies._getExpiresDate(options.expires)`', function () {
            options = { expires: '01/01/2013' };
            
            spyOn(Cookies, '_getExpiresDate').andCallThrough();
            
            Cookies.set(key, value, options);
            expect(Cookies._getExpiresDate).toHaveBeenCalledWith(options.expires);
            
            Cookies.set(key, 0, options);
            expect(Cookies._getExpiresDate).toHaveBeenCalledWith(options.expires);
        });
        
        it('calls `Cookies._getExpiresDate(-1)` when value is `undefined`', function () {
            options = { expires: '01/01/2013' };
            
            spyOn(Cookies, '_getExpiresDate').andCallThrough();
            Cookies.set(key, undefined, options);
            
            expect(Cookies._getExpiresDate).toHaveBeenCalledWith(-1);
        });
        
        it('calls `Cookies._generateCookieString(key, value, options)` with extended options and options.expires as a Date instance', function () {
            var extendedOptionsWithExpiresDate = {
                path: Cookies.defaults.path,
                domain: Cookies.defaults.domain,
                expires: new Date(Cookies.defaults.expires),
                secure: Cookies.defaults.secure
            };
{'fraction_non_alphanumeric': 0.13229402543110957, 'fraction_numerical': 0.004615920571329037, 'mean_word_length': 1.7952775073028238, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '618331', 'n_tokens_mistral': 3173, 'n_tokens_neox': 3016, 'n_words': 551}