1 2 3 4 5 6 7 8 | describe("The 'toBe' matcher compares with ===", function() { it("and has a positive case ", function() { expect(true).toBe(true); }); it("and can have a negative case", function() { expect(false).not.toBe(true); }); }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | describe("Included matchers:", function() { it("The 'toBe' Matcher", function() { var a = 3.6; var b = a; expect(a).toBe(b); expect(a).not.toBe(null); }); describe("The 'toEqual' matcher", function() { it("works for simple literals and variables", function() { var a = "varA"; expect(a).toEqual("varA"); }); it("Work for objects", function() { var obj = { a: 1, b: 4 }; var obj2 = { a: 1, b: 4 }; expect(obj).toEqual(obj2); }); }); it("The 'toBeDefined' matcher ", function() { var obj = { defined: 'defined' }; expect(obj.defined).toBeDefined(); expect(obj.undefined).not.toBeDefined(); }); }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | toBe() toNotBe() toBeDefined() toBeUndefined() toBeNull() toBeTruthy() toBeFalsy() toBeLessThan() toBeGreaterThan() toEqual() toNotEqual() toContain() toBeCloseTo() toHaveBeenCalled() toHaveBeenCalledWith() toMatch() toNotMatch() toThrow() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | describe("An example of setup and teardown)", function() { var gVar; beforeEach(function() { gVar = 3.6; gVar += 1; }); afterEach(function() { gVar = 0; }); it("after setup, gVar has new value.", function() { expect(gVar).toEqual(4.6); }); it("A spec contains 2 expectations.", function() { gVar = 0; expect(gVar).toEqual(0); expect(true).toEqual(true); }); }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | describe("A spec", function() { var gVar; beforeEach(function() { gVar = 3.6; gVar += 1; }); afterEach(function() { gVar = 0; }); it("after setup, gVar has new value.", function() { expect(gVar).toEqual(4.6); }); it("A spec contains 2 expectations.", function() { gVar = 0; expect(gVar).toEqual(0); expect(true).toEqual(true); }); describe("nested describe", function() { var tempVar; beforeEach(function() { tempVar = 4.6; }); it("gVar is global scope, tempVar is this describe scope.", function() { expect(gVar).toEqual(tempVar); }); }); }); |
1 2 3 4 5 6 7 8 9 10 11 12 | xdescribe("An example of xdescribe.", function() { var gVar; beforeEach(function() { gVar = 3.6; gVar += 1; }); xit(" and xit", function() { expect(gVar).toEqual(4.6); }); }); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |