Skip to content

CH11: Testing Controllers with Authentication #55

@Waddas

Description

@Waddas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions