timoxley / functional-javascript-workshop

A functional javascript workshop. No libraries required (i.e. no underscore), just ES5.
2.06k stars 439 forks source link

async loops testing built in solution, not user's. #95

Open Ryan1729 opened 9 years ago

Ryan1729 commented 9 years ago

A pass is reported whenever the user's file exports a function that does not throw an error, for example:

module.exports = function(){}; 

and if I edit the built in solution to this:

function loadUsers(userIds, load, done) {
  var completed = 0
  var users = []
  userIds.forEach(function(id, index) {
    load(id, function(user) {
      users[index] = 42;//user
      if (++completed === userIds.length) return done(users)
    })
  })
}

module.exports = loadUsers

then I get a fail message like the following

[ 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42 ]
✗ expected: 
[ { id: 888, name: 'Elit veniam' },
  { id: 1000, name: 'Labore magna' },
  { id: 154, name: 'Sit commodo' },
  { id: 400, name: 'Magna Lorem' },
  { id: 399, name: 'Aliqua esse' },
  { id: 853, name: 'Non non' },
  { id: 124, name: 'Laboris incididunt' },
  { id: 193, name: 'Ex commodo' },
  { id: 983, name: 'Nostrud duis' },
  { id: 917, name: 'Pariatur cillum' },
  { id: 915, name: 'Cillum ullamco' },
  { id: 666, name: 'Ex velit' },
  { id: 94, name: 'Aliquip reprehenderit' } ]
 but got:
[ 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42 ]

# FAIL

Your solution to Async Loops didn't pass. Try again!
timoxley commented 9 years ago

lol, whoops, I'll look into it, thanks for reporting

swinston100 commented 8 years ago

I think there is still somethign wrong with this test as

function loadUsers(userIds, load, done) {

  done = usersIDs.foreach(function(userID){
    return load(userID)
  });
  return done
}

module.exports = **loadUsers**

and there is no way this is proper functional coding and it is not taking into account the instructions!