angular/modules/benchpress/test/reporter/multi_reporter_spec.js
Victor Berchet 33b5ba863e feat(tests): add a test injector
fixes #614

Asynchronous test should inject an AsyncTestCompleter:

Before:

  it("async test", (done) => {
    // ...
    done();
  });

After:

  it("async test", inject([AsyncTestCompleter], (async) => {
    // ...
    async.done();
  }));

Note: inject() is currently a function and the first parameter is the
array of DI tokens to inject as the test function parameters. This
construct is linked to Traceur limitations. The planned syntax is:

  it("async test", @Inject (async: AsyncTestCompleter) => {
    // ...
    async.done();
  });
2015-03-13 18:20:02 +01:00

90 lines
2.3 KiB
JavaScript

import {
afterEach,
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from 'angular2/test_lib';
import { List, ListWrapper, StringMap } from 'angular2/src/facade/collection';
import { PromiseWrapper, Promise } from 'angular2/src/facade/async';
import { DateWrapper } from 'angular2/src/facade/lang';
import { Reporter, MultiReporter, bind, Injector, MeasureValues } from 'benchpress/common';
export function main() {
function createReporters(ids) {
return new Injector([
ListWrapper.map(ids, (id) => bind(id).toValue(new MockReporter(id)) ),
MultiReporter.createBindings(ids)
]).asyncGet(MultiReporter);
}
describe('multi reporter', () => {
it('should reportMeasureValues to all', inject([AsyncTestCompleter], (async) => {
var mv = new MeasureValues(0, DateWrapper.now(), {});
createReporters(['m1', 'm2'])
.then( (r) => r.reportMeasureValues(mv) )
.then( (values) => {
expect(values).toEqual([
{'id': 'm1', 'values': mv},
{'id': 'm2', 'values': mv}
]);
async.done();
});
}));
it('should reportSample to call', inject([AsyncTestCompleter], (async) => {
var completeSample = [
new MeasureValues(0, DateWrapper.now(), {}),
new MeasureValues(1, DateWrapper.now(), {})
];
var validSample = [completeSample[1]];
createReporters(['m1', 'm2'])
.then( (r) => r.reportSample(completeSample, validSample) )
.then( (values) => {
expect(values).toEqual([
{'id': 'm1', 'completeSample': completeSample, 'validSample': validSample},
{'id': 'm2', 'completeSample': completeSample, 'validSample': validSample}
]);
async.done();
})
}));
});
}
class MockReporter extends Reporter {
_id:string;
constructor(id) {
super();
this._id = id;
}
reportMeasureValues(values:MeasureValues):Promise {
return PromiseWrapper.resolve({
'id': this._id,
'values': values
});
}
reportSample(completeSample:List<MeasureValues>, validSample:List<MeasureValues>):Promise {
return PromiseWrapper.resolve({
'id': this._id,
'completeSample': completeSample,
'validSample': validSample
});
}
}