Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let list = require('../second.js')
- let assert = require('chai').assert
- describe('Add delete list functionality tests', function(){
- let demo
- beforeEach(function(){
- demo = list.list
- })
- describe('add item tests',function(){
- it('it should initialize the list',function(){
- demo.add(1)
- assert(demo.list.toString()==='1','dosent initialize a list')
- })
- it('it should initialize and add multiple elems to the list',function(){
- demo.add(1)
- demo.add(2)
- demo.add('pesho')
- assert.equal(demo.toString(),'1, 2, pesho','dosent initialize a list')
- })
- })
- })
- // the function
- let list = (function () {
- let data = []
- return {
- add: function (item) {
- data.push(item)
- },
- delete: function (index) {
- if (Number.isInteger(index) && index >= 0 && index < data.length) {
- return data.splice(index, 1)[0]
- } else {
- return undefined
- }
- },
- toString: function () {
- return data.join(', ')
- }
- }
- })()
- module.exports = {list}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement