Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const StringBulder = require('./theCode');
  2. const assert = require('chai').assert;
  3.  
  4. describe('StringBuilder',function(){
  5. let str
  6.         beforeEach(()=>{
  7.                 str = new StringBulder('test');
  8.         })
  9.     it('should be instantiated with a passed in string argument ',()=>{
  10.             let actual = JSON.stringify(str);
  11.             let expected = '{"_stringArray":["t","e","s","t"]}';
  12.             assert.equal(actual,expected);
  13.     })    
  14.     it('should be instantiated without anything',()=>{
  15.             let temp = new StringBulder();
  16.             let actual = JSON.stringify(temp);
  17.             let expected = '{"_stringArray":[]}';
  18.             assert.equal(actual,expected);
  19.     });
  20.     it('should converts the passed in string argument to an array and adds it to the end of the storage',()=>{
  21.         str.append(', there');
  22.         let actual = JSON.stringify(str);
  23.         let expected = '{"_stringArray":["t","e","s","t",","," ","t","h","e","r","e"]}';
  24.         assert.equal(actual,expected);
  25.     });
  26.     it('should converts the passed in string argument to an array and adds it to the beginning of the storage',()=>{
  27.         str.prepend('User, ');
  28.         let actual = JSON.stringify(str);
  29.        let expected = '{"_stringArray":["U","s","e","r",","," ","t","e","s","t"]}';
  30.        assert.equal(actual,expected);
  31.        
  32.     });
  33.     it('should converts the passed in string argument to an array and adds it at the given index',()=>{
  34.         str.insertAt('woop',5 );
  35.         let actual = JSON.stringify(str);
  36.         let expected = '{"_stringArray":["t","e","s","t","w","o","o","p"]}';
  37.         assert.equal(actual,expected);        
  38.     });
  39.     it('should removes elements from the storage, starting at the given index (inclusive)',()=>{
  40.         str.remove(6, 3);
  41.         let actual = JSON.stringify(str);
  42.         let expected = '{"_stringArray":["t","e","s","t"]}';
  43.         assert.equal(actual,expected);    
  44.     });
  45.     it('should returns a string with all elements joined by an empty string ',()=>{
  46.         str.append(', there');
  47.         str.prepend('User, ');
  48.         str.insertAt('woop',5 );
  49.         str.remove(6, 3);
  50.         let actual = str
  51.         let expected = 'User,w test, there';
  52.         assert.equal(actual.toString(),expected);
  53.     });
  54.  
  55. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement