2009-09-30 05:09:30 +00:00
|
|
|
describe('jasmine.jsApiReporter', function() {
|
2009-09-28 18:13:44 +00:00
|
|
|
describe('results', function () {
|
2009-09-30 05:09:30 +00:00
|
|
|
var reporter, spec1, spec2, spec3, expectedSpec1Results, expectedSpec2Results;
|
2010-06-22 17:18:22 +00:00
|
|
|
var env;
|
|
|
|
var suite, nestedSuite, nestedSpec;
|
2009-09-28 18:13:44 +00:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2010-06-22 17:18:22 +00:00
|
|
|
env = new jasmine.Env();
|
2009-10-06 05:36:10 +00:00
|
|
|
env.updateInterval = 0;
|
2009-09-30 05:09:30 +00:00
|
|
|
|
2010-06-22 17:18:22 +00:00
|
|
|
suite = env.describe("top-level suite", function() {
|
|
|
|
spec1 = env.it("spec 1", function() {
|
|
|
|
this.expect(true).toEqual(true);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
spec2 = env.it("spec 2", function() {
|
|
|
|
this.expect(true).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
nestedSuite = env.describe("nested suite", function() {
|
|
|
|
nestedSpec = env.it("nested spec", function() {
|
|
|
|
expect(true).toEqual(true);
|
2011-02-26 23:07:59 +00:00
|
|
|
});
|
2010-06-22 17:18:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
spec3 = env.it("spec 3", function() {
|
|
|
|
this.log('some debug message');
|
|
|
|
});
|
|
|
|
});
|
2009-09-28 18:13:44 +00:00
|
|
|
|
|
|
|
reporter = new jasmine.JsApiReporter();
|
2010-06-22 17:18:22 +00:00
|
|
|
env.addReporter(reporter);
|
|
|
|
|
|
|
|
env.execute();
|
2010-06-22 19:04:34 +00:00
|
|
|
|
|
|
|
expectedSpec1Results = {
|
|
|
|
messages: spec1.results().getItems(),
|
|
|
|
result: "passed"
|
|
|
|
};
|
|
|
|
expectedSpec2Results = {
|
|
|
|
messages: spec2.results().getItems(),
|
|
|
|
result: "failed"
|
|
|
|
};
|
2009-09-28 18:13:44 +00:00
|
|
|
});
|
|
|
|
|
2010-06-22 19:04:34 +00:00
|
|
|
it('resultForSpec() should return the result for the given spec', function () {
|
2009-09-28 18:13:44 +00:00
|
|
|
expect(reporter.resultsForSpec(spec1.id)).toEqual(expectedSpec1Results);
|
|
|
|
expect(reporter.resultsForSpec(spec2.id)).toEqual(expectedSpec2Results);
|
|
|
|
});
|
|
|
|
|
2010-06-22 19:04:34 +00:00
|
|
|
it('results() should return a hash of all results, indexed by spec id', function () {
|
2009-09-28 18:13:44 +00:00
|
|
|
expect(reporter.results()[spec1.id]).toEqual(expectedSpec1Results);
|
|
|
|
expect(reporter.results()[spec2.id]).toEqual(expectedSpec2Results);
|
|
|
|
});
|
|
|
|
|
2010-06-22 17:18:22 +00:00
|
|
|
it("should return nested suites as children of their parents", function() {
|
|
|
|
expect(reporter.suites()).toEqual([
|
|
|
|
{ id: 0, name: 'top-level suite', type: 'suite',
|
|
|
|
children: [
|
|
|
|
{ id: 0, name: 'spec 1', type: 'spec', children: [ ] },
|
|
|
|
{ id: 1, name: 'spec 2', type: 'spec', children: [ ] },
|
|
|
|
{ id: 1, name: 'nested suite', type: 'suite',
|
|
|
|
children: [
|
|
|
|
{ id: 2, name: 'nested spec', type: 'spec', children: [ ] }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{ id: 3, name: 'spec 3', type: 'spec', children: [ ] }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2010-06-22 19:04:34 +00:00
|
|
|
describe("#summarizeResult_", function() {
|
2009-09-30 05:09:30 +00:00
|
|
|
it("should summarize a passing result", function() {
|
|
|
|
var result = reporter.results()[spec1.id];
|
|
|
|
var summarizedResult = reporter.summarizeResult_(result);
|
|
|
|
expect(summarizedResult.result).toEqual('passed');
|
|
|
|
expect(summarizedResult.messages.length).toEqual(1);
|
|
|
|
expect(summarizedResult.messages[0].message).toEqual(result.messages[0].message);
|
|
|
|
expect(summarizedResult.messages[0].passed).toBeTruthy();
|
2010-06-22 21:48:47 +00:00
|
|
|
expect(summarizedResult.messages[0].type).toEqual('expect');
|
2010-06-22 19:23:54 +00:00
|
|
|
expect(summarizedResult.messages[0].text).toBeUndefined();
|
|
|
|
expect(summarizedResult.messages[0].trace.stack).toBeUndefined();
|
2009-09-30 05:09:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should have a stack trace for failing specs", function() {
|
|
|
|
var result = reporter.results()[spec2.id];
|
|
|
|
var summarizedResult = reporter.summarizeResult_(result);
|
|
|
|
expect(summarizedResult.result).toEqual('failed');
|
|
|
|
expect(summarizedResult.messages[0].trace.stack).toEqual(result.messages[0].trace.stack);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should have messages for specs with messages", function() {
|
|
|
|
var result = reporter.results()[spec3.id];
|
|
|
|
var summarizedResult = reporter.summarizeResult_(result);
|
|
|
|
expect(summarizedResult.result).toEqual('passed');
|
2010-06-22 21:48:47 +00:00
|
|
|
expect(summarizedResult.messages[0].type).toEqual('log');
|
2009-09-30 05:09:30 +00:00
|
|
|
expect(summarizedResult.messages[0].text).toEqual('some debug message');
|
|
|
|
});
|
|
|
|
});
|
2009-09-28 18:13:44 +00:00
|
|
|
});
|
|
|
|
});
|