You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given the following functions, write a set of unit tests that will test for the following:
Is the function defined?
Does the function return the correct output when the input is correct?
Does the function throw an error when the input is incorrect?
Does the function throw an error when the input is undefined?
describe('fetchFromDatabase',()=>{it('should return a user when a valid id is passed in',(done)=>{fetchFromDatabase('1').then((data)=>{expect(data).to.deep.equal({name: 'Spruce '});done();});});});
letasyncSortArray=function(arr,cb){if(!arr||!Array.isArray(arr)){cb(newError('not an array'),null);return;}letsortedArr=arr.slice().sort();cb(null,sortedArr);}
Exercise 3
letfetchFromDatabase=function(userId){constusers={'1': {name: 'Spruce'},'2': {name: 'Brenna'}};returnnewPromise(function(resolve,reject){if(!userId&&typeofuserId!=='string'){returnreject('invalid parameters!');}constuser=users[userId];if(user){returnresolve(user);}else{returnreject('user not found');}});}