一. describe测试包(官方称之为suite)
describe 是 Jasmine 的全局函数,作为一个 Test Suite 的开始,它通常有 2 个参数:字符串和方法。字符串作为特定 Suite 的名字和标题。方法是包含实现 Suite 的代码。
describe("This is an exmaple suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
expect(false).toBe(false);
expect(false).not.toBe(true);
});
});
二. it测试用例(官方称之为spec)
和 describe 类似,it 也是有 2 个参数,字符串和方法。每个 Spec 包含一个或多个 expectations 来测试需要测试代码。Jasmine 中的每个 expectation 是一个断言,可以是 true 或者 false。当每个 Spec 中的所有 expectations 都是 true,则通过测试。有任何一个 expectation 是 false,则未通过测试。而方法的内容就是测试主体。
it("a spec with an expectation", function() {
expect(1).toBe(1);
expect(1===1).toBe(true);
expect("a").not.toBe("b");
});
三.Expectations.断言表达式
注意:
1、每个测试文件中可以包含多个describe
2、每个describe中可以包含多个it
3、每个it中可以包含多个expect
4、describe可嵌套使用