What is “assert” in JavaScript?

后端 未结 14 726
-上瘾入骨i
-上瘾入骨i 2020-12-04 05:03

What does assert mean in JavaScript?

I’ve seen something like:

assert(function1() && function2() && function3(), \"some          


        
14条回答
  •  情话喂你
    2020-12-04 05:22

    If you use webpack, you can just use the node.js assertion library. Although they claim that it's "not intended to be a general purpose assertion library", it seems to be more than OK for ad hoc assertions, and it seems no competitor exists in the Node space anyway (Chai is designed for unit testing).

    const assert = require('assert');
    ...
    assert(jqXHR.status == 201, "create response should be 201");
    

    You need to use webpack or browserify to be able to use this, so obviously this is only useful if those are already in your workflow.

提交回复
热议问题