1 | describe("The 'toBe' matcher compares with ===", () => {
|
2 | it("and has a positive case ", () => {
|
3 | expect(true).toBe(true);
|
4 | });
|
5 | it("and can have a negative case", () => {
|
6 | expect(false).not.toBe(true);
|
7 | });
|
8 | });
|
9 |
|
10 | describe("Included matchers:", () => {
|
11 | it("The 'toBe' matcher compares with ===", () => {
|
12 | var a = 12;
|
13 | var b = a;
|
14 | expect(a).toBe(b);
|
15 | expect(a).not.toBe(null);
|
16 | });
|
17 | describe("The 'toEqual' matcher", () => {
|
18 | it("works for simple literals and variables", () => {
|
19 | var a = 12;
|
20 | expect(a).toEqual(12);
|
21 | });
|
22 | it("should work for objects", () => {
|
23 | var foo = {
|
24 | a: 12,
|
25 | b: 34
|
26 | };
|
27 | var bar = {
|
28 | a: 12,
|
29 | b: 34
|
30 | };
|
31 | expect(foo).toEqual(bar);
|
32 | });
|
33 | });
|
34 |
|
35 | it("The 'toMatch' matcher is for regular expressions", () => {
|
36 | var message = 'foo bar baz';
|
37 | expect(message).toMatch(/bar/);
|
38 | expect(message).toMatch('bar');
|
39 | expect(message).not.toMatch(/quux/);
|
40 | });
|
41 |
|
42 | it("The 'toBeDefined' matcher compares against `undefined`", () => {
|
43 | var a = {
|
44 | foo: 'foo'
|
45 | };
|
46 | expect(a.foo).toBeDefined();
|
47 | expect((<any>a).bar).not.toBeDefined();
|
48 | });
|
49 |
|
50 | it("The `toBeUndefined` matcher compares against `undefined`", () => {
|
51 | var a = {
|
52 | foo: 'foo'
|
53 | };
|
54 | expect(a.foo).not.toBeUndefined();
|
55 | expect((<any>a).bar).toBeUndefined();
|
56 | });
|
57 |
|
58 | it("The 'toBeNull' matcher compares against null", () => {
|
59 | var a: string = null;
|
60 | var foo = 'foo';
|
61 | expect(null).toBeNull();
|
62 | expect(a).toBeNull();
|
63 | expect(foo).not.toBeNull();
|
64 | });
|
65 |
|
66 | it("The 'toBeTruthy' matcher is for boolean casting testing", () => {
|
67 | var a: string, foo = 'foo';
|
68 | expect(foo).toBeTruthy();
|
69 | expect(a).not.toBeTruthy();
|
70 | });
|
71 |
|
72 | it("The 'toBeFalsy' matcher is for boolean casting testing", () => {
|
73 | var a: string, foo = 'foo';
|
74 | expect(a).toBeFalsy();
|
75 | expect(foo).not.toBeFalsy();
|
76 | });
|
77 |
|
78 | it("The 'toContain' matcher is for finding an item in an Array", () => {
|
79 | var a = ['foo', 'bar', 'baz'];
|
80 | expect(a).toContain('bar');
|
81 | expect(a).not.toContain('quux');
|
82 | });
|
83 |
|
84 | it("The 'toBeLessThan' matcher is for mathematical comparisons", () => {
|
85 | var pi = 3.1415926, e = 2.78;
|
86 | expect(e).toBeLessThan(pi);
|
87 | expect(pi).not.toBeLessThan(e);
|
88 | });
|
89 |
|
90 | it("The 'toBeGreaterThan' is for mathematical comparisons", () => {
|
91 | var pi = 3.1415926, e = 2.78;
|
92 | expect(pi).toBeGreaterThan(e);
|
93 | expect(e).not.toBeGreaterThan(pi);
|
94 | });
|
95 |
|
96 | it("The 'toBeCloseTo' matcher is for precision math comparison", () => {
|
97 | var pi = 3.1415926, e = 2.78;
|
98 | expect(pi).not.toBeCloseTo(e, 1);
|
99 | expect(pi).toBeCloseTo(e, 0);
|
100 | });
|
101 |
|
102 | it("The 'toThrow' matcher is for testing if a function throws an exception", () => {
|
103 | var foo = () => {
|
104 | return 1 + 2;
|
105 | };
|
106 | var bar = () => {
|
107 | throw new Error();
|
108 | };
|
109 | expect(foo).not.toThrow();
|
110 | expect(bar).toThrow();
|
111 | });
|
112 | });
|