jdx / mean-sample

Sample project for Write Modern Web Apps with the MEAN Stack by Jeff Dickey
https://mean-sample.herokuapp.com
166 stars 90 forks source link

CH11: Testing Controllers with Authentication #55

Open Waddas opened 6 years ago

Waddas commented 6 years ago

When running mocha on the updated test/server/controllers/api/posts.spec.js file, the test fails with the following error:

 2 passing (287ms)
  1 failing

  1) controllers.api.posts
       POST /api/posts
         "before each" hook:
     Uncaught TypeError: websockets.broadcast is not a function
      at controllers/api/posts.js:41:13
      at RedisClient.<anonymous> (pubsub.js:12:3)
      at return_pub_sub (node_modules/redis/index.js:786:18)
      at RedisClient.return_reply (node_modules/redis/index.js:833:9)
      at JavascriptRedisParser.returnReply (node_modules/redis/index.js:192:18)
      at JavascriptRedisParser.execute (node_modules/redis-parser/lib/parser.js:574:12)
      at Socket.<anonymous> (node_modules/redis/index.js:274:27)
      at readableAddChunk (_stream_readable.js:176:18)
      at Socket.Readable.push (_stream_readable.js:134:10)
      at TCP.onread (net.js:547:20)

In the controllers/api/posts.js file, this is where the code breaks:

pubsub.subscribe('new_post', function(post) {
    websockets.broadcast('new_post', post)
})

My guess is that websockets is not available to the testing code, but i'm unsure on how to resolve this.