zblueslip: Improve usage documentation in test file.

This commit is contained in:
Rohitt Vashishtha
2018-04-24 04:01:22 +05:30
committed by Tim Abbott
parent bddb6a1a14
commit c43f4e509c

View File

@@ -15,6 +15,8 @@ The code we are testing lives here:
https://github.com/zulip/zulip/blob/master/frontend_tests/zjsunit/zblueslip.js
Read the following contents for an overview of how zblueslip works. Also take a
look at `node_tests/people_errors.js` for actual usage of this module.
*/
@@ -23,6 +25,11 @@ The code we are testing lives here:
// zblueslip stub variable.
set_global('blueslip', global.make_zblueslip());
// Aditionally, you can specify which functions you want to test for/ignore.
// By default, we ignore debug, log and info. To test for debug, for example, do:
// set_global('blueslip', global.make_zblueslip({debug: true}));
// Similarly, you can ignore tests for errors by passing {debug: true, error: false}.
(function test_basics() {
// Let's create a sample piece of code to test:
function throw_an_error() {
@@ -34,12 +41,9 @@ set_global('blueslip', global.make_zblueslip());
// of messages expected for that log type; here, 'error'.
blueslip.set_test_data('error', 'hello');
// Since the error 'world' is not being expected, blueslip will
// throw an error. This can be verified automatically with the
// blueslip.check_error() call.
// blueslip.check_error() takes the argument `isblueslip` which asserts that the
// error was thrown by blueslip, or in other words, was not in the expected list
// of errors.
// throw an error.
assert.throws(throw_an_error);
// zblueslip logs all the calls made to it, and they can be used in asserts like:
assert.equal(blueslip.get_test_logs('error').length, 1);
// Now, let's add our error to the list of expected errors.