Advertisement
xapu

Untitled

Jul 20th, 2017
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. let list = require('../second.js')
  2. let assert = require('chai').assert
  3.  
  4.  
  5. describe('Add delete list functionality tests', function(){
  6.  
  7. let demo
  8.  
  9. beforeEach(function(){
  10. demo = list.list
  11. })
  12. describe('add item tests',function(){
  13. it('it should initialize the list',function(){
  14. demo.add(1)
  15. assert(demo.list.toString()==='1','dosent initialize a list')
  16. })
  17.  
  18. it('it should initialize and add multiple elems to the list',function(){
  19. demo.add(1)
  20. demo.add(2)
  21. demo.add('pesho')
  22. assert.equal(demo.toString(),'1, 2, pesho','dosent initialize a list')
  23. })
  24. })
  25. })
  26.  
  27.  
  28.  
  29. // the function
  30.  
  31. let list = (function () {
  32. let data = []
  33. return {
  34. add: function (item) {
  35. data.push(item)
  36. },
  37. delete: function (index) {
  38. if (Number.isInteger(index) && index >= 0 && index < data.length) {
  39. return data.splice(index, 1)[0]
  40. } else {
  41. return undefined
  42. }
  43. },
  44. toString: function () {
  45. return data.join(', ')
  46. }
  47. }
  48. })()
  49.  
  50. module.exports = {list}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement