Blame view

framework/thirdparty/jasmine/spec/suites/SpecSpec.js 3.73 KB
0084d336   Administrator   Importers CRUD
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  describe('Spec', function () {
    var env, suite;
    beforeEach(function() {
      env = new jasmine.Env();
      env.updateInterval = 0;
      suite = new jasmine.Suite(env, 'suite 1');
    });
  
    describe('initialization', function () {
  
      it('should raise an error if an env is not passed', function () {
        try {
          new jasmine.Spec();
        }
        catch (e) {
          expect(e.message).toEqual('jasmine.Env() required');
        }
      });
  
      it('should raise an error if a suite is not passed', function () {
        try {
          new jasmine.Spec(env);
        }
        catch (e) {
          expect(e.message).toEqual('jasmine.Suite() required');
        }
      });
  
      it('should assign sequential ids for specs belonging to the same env', function () {
        var spec1 = new jasmine.Spec(env, suite);
        var spec2 = new jasmine.Spec(env, suite);
        var spec3 = new jasmine.Spec(env, suite);
        expect(spec1.id).toEqual(0);
        expect(spec2.id).toEqual(1);
        expect(spec3.id).toEqual(2);
      });
    });
  
    it('getFullName returns suite & spec description', function () {
      var spec = new jasmine.Spec(env, suite, 'spec 1');
      expect(spec.getFullName()).toEqual('suite 1 spec 1.')
    });
  
    describe('results', function () {
      var spec, results;
      beforeEach(function () {
        spec = new jasmine.Spec(env, suite);
        results = spec.results();
        expect(results.totalCount).toEqual(0);
        spec.runs(function () {
          this.expect(true).toEqual(true);
          this.expect(true).toEqual(true);
        });
      });
  
  
      it('results shows the total number of expectations for each spec after execution', function () {
        expect(results.totalCount).toEqual(0);
        spec.execute();
        expect(results.totalCount).toEqual(2);
      });
  
      it('results shows the number of passed expectations for each spec after execution', function () {
        expect(results.passedCount).toEqual(0);
        spec.execute();
        expect(results.passedCount).toEqual(2);
      });
  
      it('results shows the number of failed expectations for each spec after execution', function () {
        spec.runs(function () {
          this.expect(true).toEqual(false);
        });
        expect(results.failedCount).toEqual(0);
        spec.execute();
        expect(results.failedCount).toEqual(1);
      });
  
      describe('results.passed', function () {
        it('is true if all spec expectations pass', function () {
          spec.runs(function () {
            this.expect(true).toEqual(true);
          });
          spec.execute();
          expect(results.passed()).toEqual(true);
        });
  
        it('is false if one spec expectation fails', function () {
          spec.runs(function () {
            this.expect(true).toEqual(false);
          });
          spec.execute();
          expect(results.passed()).toEqual(false);
        });
  
        it('a spec with no expectations will return true', function () {
          var specWithoutExpectations = new jasmine.Spec(env, suite);
          specWithoutExpectations.runs(function() {
  
          });
          specWithoutExpectations.execute();
          expect(results.passed()).toEqual(true);
        });
  
        it('an unexecuted spec will return true', function () {
          expect(results.passed()).toEqual(true);
        });
      });
  
      it("includes log messages, which may contain arbitary objects", function() {
        spec.runs(function() {
          this.log("here's some log message", {key: 'value'}, 123);
        });
        spec.execute();
        var items = results.getItems();
        expect(items).toEqual([
            jasmine.any(jasmine.ExpectationResult),
            jasmine.any(jasmine.ExpectationResult),
            jasmine.any(jasmine.MessageResult)
        ]);
        var logResult = items[2];
        expect(logResult.values).toEqual(["here's some log message", {key: 'value'}, 123]);
      });
    });
  });