Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const StringBulder = require('./theCode');
- const assert = require('chai').assert;
- describe('StringBuilder',function(){
- let str
- beforeEach(()=>{
- str = new StringBulder('test');
- })
- it('should be instantiated with a passed in string argument ',()=>{
- let actual = JSON.stringify(str);
- let expected = '{"_stringArray":["t","e","s","t"]}';
- assert.equal(actual,expected);
- })
- it('should be instantiated without anything',()=>{
- let temp = new StringBulder();
- let actual = JSON.stringify(temp);
- let expected = '{"_stringArray":[]}';
- assert.equal(actual,expected);
- });
- it('should converts the passed in string argument to an array and adds it to the end of the storage',()=>{
- str.append(', there');
- let actual = JSON.stringify(str);
- let expected = '{"_stringArray":["t","e","s","t",","," ","t","h","e","r","e"]}';
- assert.equal(actual,expected);
- });
- it('should converts the passed in string argument to an array and adds it to the beginning of the storage',()=>{
- str.prepend('User, ');
- let actual = JSON.stringify(str);
- let expected = '{"_stringArray":["U","s","e","r",","," ","t","e","s","t"]}';
- assert.equal(actual,expected);
- });
- it('should converts the passed in string argument to an array and adds it at the given index',()=>{
- str.insertAt('woop',5 );
- let actual = JSON.stringify(str);
- let expected = '{"_stringArray":["t","e","s","t","w","o","o","p"]}';
- assert.equal(actual,expected);
- });
- it('should removes elements from the storage, starting at the given index (inclusive)',()=>{
- str.remove(6, 3);
- let actual = JSON.stringify(str);
- let expected = '{"_stringArray":["t","e","s","t"]}';
- assert.equal(actual,expected);
- });
- it('should returns a string with all elements joined by an empty string ',()=>{
- str.append(', there');
- str.prepend('User, ');
- str.insertAt('woop',5 );
- str.remove(6, 3);
- let actual = str
- let expected = 'User,w test, there';
- assert.equal(actual.toString(),expected);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement