jList: listAppend Test

Example of using Jasmine to test the listAppend function from the jList library.

by David Waterston

HTML

<script src="http://searls.github.com/jasmine-all/jasmine-all-min.js"></script>
<script src="https://rawgithub.com/davidwaterston/jList/master/jlist-min.js"></script>

JavaScript

describe( 'listAppend: Concatenates an element to a list.', function () {  

    it ('01. Throws an error when no parameters are passed in', function () {  
        expect( function(){ jList.listAppend(); } ).toThrow('Missing parameter: list and value must be provided');  
    }); 

    it ('02. Throws an error when only 1 parameter is passed in', function () {  
        expect( function(){ jList.listAppend('cat,dog'); } ).toThrow('Missing parameter: list and value must be provided');  
    }); 

    it ('03. Concatenates an element to an empty list that uses the default delimiter', function () {  
        expect( jList.listAppend('', 'rabbit') ).toEqual('rabbit');  
    }); 

    it ('04. Concatenates an element to a list  that uses the default delimiter and is populated with a single element', function () {  
        expect( jList.listAppend('cat', 'rabbit') ).toEqual('cat,rabbit');  
    }); 

    it ('05. Concatenates an element to a list  that uses the default delimiter and is populated with multiple elements', function () {  
        expect( jList.listAppend('cat,dog', 'rabbit' ) ).toEqual('cat,dog,rabbit');  
    }); 

    it ('06. Concatenates an element to an empty list that uses a custom delimiter', function () {  
        expect( jList.listAppend('', 'rabbit', '~') ).toEqual('rabbit');  
    }); 

    it ('07. Concatenates an element to a list that uses a custom delimiter and is populated with a single element', function () {  
        expect( jList.listAppend('cat', 'rabbit', '~') ).toEqual('cat~rabbit');  
    }); 

    it ('08. Concatenates an element to a list that uses a custom delimiter and is populated with multiple elements', function () {  
        expect( jList.listAppend('cat~dog', 'rabbit', '~') ).toEqual('cat~dog~rabbit');  
    }); 

  });