t_sh0w

03.StringOperations

Apr 7th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. const { expect } = require('chai');
  2. const stringOperations = require('./03.StringOperations');
  3.  
  4. describe('StringOperations', () => {
  5. it('stringSlicer', () => {
  6. const str1 = 'Pesho';
  7. const str2 = 'Pe'
  8. expect(stringOperations.stringSlicer(str1)).to.equal('Pes...');
  9. expect(stringOperations.stringSlicer(str2)).to.equal('Pe...');
  10. });
  11.  
  12. it('wordChecker', () => {
  13. const word1 = 'Pesho';
  14. const text1 = 'Pesho e ot selo';
  15. const text2 = 'Gosho e ot selo';
  16. expect(stringOperations.wordChecker(word1, text1)).to.equal('pesho');
  17. expect(stringOperations.wordChecker(word1, text2)).to.equal(`${word1.toLowerCase()} not found!`);
  18. });
  19.  
  20. it('printEveryNthElement', () => {
  21. const n1 = 2;
  22. const n2 = 'asfsfa';
  23. const arr1 = ['a', 'b', 'c', 'd'];
  24. const arr2 = true;
  25. expect(stringOperations.printEveryNthElement(n1, arr1)).to.deep.equal(['a', 'c']);
  26. expect(() => stringOperations.printEveryNthElement(n2, arr1)).to.throw('The input is not valid!');
  27. expect(() => stringOperations.printEveryNthElement(n1, arr2)).to.throw('The input is not valid!');
  28. expect(() => stringOperations.printEveryNthElement(n2, arr2)).to.throw('The input is not valid!');
  29. });
  30. });
Advertisement
Add Comment
Please, Sign In to add comment