CH11: Testing Controllers with Authentication
- Dominant language
- JavaScript
- Stars
- 165
- Forks
- 81
- PR merge metrics
- No merged PRs in 30d
Description
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. (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. (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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.