Jasmine里的describe,it和expect函数

describe

将一系列业务相关的specs关联在一起,每个测试实现文件的top level至少有一个describe. 字符串参数是为了命名这些spec的集合。

The describe function is for grouping related specs, typically each test file has one at the top level. The string parameter is for naming the collection of specs, and will be concatenated with specs to make a spec’s full name.

例子:

Jasmine里的describe,it和expect函数

it

使用it函数定义spec,一个spec里包含了一个或者多个expectation.

Jasmine里的describe,it和expect函数

Expectation

An expectation in Jasmine is an assertion that is either true or false. A spec with all true expectations is a passing spec. A spec with one or more false expectations is a failing spec.

Expectation就是assertion.

JavaScript scoping rules apply, so variables declared in a describe are available to any it block inside the suite.

定义在describe里的变量可以在任意的it区块内访问。

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
Jasmine里的describe,it和expect函数