mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 15:40:22 +00:00
- By default the runner now creates multiple output formats as it runs. Nodes are created in the DOM with ids: json, xml, and html.
ex. $('#json').html() => json output of the runner
ex. $('#xml').html() => json output of the runner
$result is also an object tree result.
The permitted formats are html,json,xml,object.
If you don't want certain formats you can select specific ones with the new ng:scenario-output attribute on the script tag.
<script src="angular-scenario.js" ng:scenario-output="xml,json">
- Added element(...).count() that returns the number of matching elements for the selector.
- repeater(...).count() now returns 0 if no elements matched which can be used to check if a repeater is empty.
- Added toBe() matcher that does strict equality with ===
- Implement iit and ddescribe. If iit() is used instead of it() then only that test will run. If ddescribe() is used instead of describe() them only it() statements inside of it will run. Several iit/ddescribe() blocks can be used to run isolated tests.
- Implement new event based model for SpecRunner. You can now listen for events in the runner. This is useful for writing your own UI or connecting a remote process (ex. WebDriver). Event callbacks execute on the Runner instance.
Events, if fired, will always be in the below order. All events always happen
except for Failure and Error events which only happen in error conditions.
Events:
RunnerBegin
SpecBegin(spec)
StepBegin(spec, step)
StepError(spec, step, error)
StepFailure(spec, step, error)
StepEnd(spec, step)
SpecError(spec, step, error)
SpecEnd(spec)
RunnerEnd
- Only allow the browser to repaint every 10 steps. Cuts 700ms off Firefox in benchmark, 200ms off Chrome.
- Bug Fix: Manually navigate anchors on click since trigger wont work in Firefox.
170 lines
4 KiB
JavaScript
170 lines
4 KiB
JavaScript
/**
|
|
* Mock Application
|
|
*/
|
|
function ApplicationMock($window) {
|
|
this.$window = $window;
|
|
}
|
|
ApplicationMock.prototype = {
|
|
executeAction: function(callback) {
|
|
callback.call(this.$window, _jQuery(this.$window.document), this.$window);
|
|
}
|
|
};
|
|
|
|
describe('angular.scenario.SpecRunner', function() {
|
|
var $window, $root, log;
|
|
var runner;
|
|
|
|
function createSpec(name, body) {
|
|
return {
|
|
name: name,
|
|
before: angular.noop,
|
|
body: body || angular.noop,
|
|
after: angular.noop
|
|
};
|
|
}
|
|
|
|
beforeEach(function() {
|
|
log = [];
|
|
$window = {};
|
|
$window.setTimeout = function(fn, timeout) {
|
|
fn();
|
|
};
|
|
$root = angular.scope({
|
|
emit: function(eventName) {
|
|
log.push(eventName);
|
|
},
|
|
on: function(eventName) {
|
|
log.push('Listener Added for ' + eventName);
|
|
}
|
|
});
|
|
$root.application = new ApplicationMock($window);
|
|
$root.$window = $window;
|
|
runner = $root.$new(angular.scenario.SpecRunner);
|
|
});
|
|
|
|
it('should bind futures to the spec', function() {
|
|
runner.addFuture('test future', function(done) {
|
|
this.value = 10;
|
|
done();
|
|
});
|
|
runner.futures[0].execute(angular.noop);
|
|
expect(runner.value).toEqual(10);
|
|
});
|
|
|
|
it('should pass done to future action behavior', function() {
|
|
runner.addFutureAction('test future', function($window, $document, done) {
|
|
expect(angular.isFunction(done)).toBeTruthy();
|
|
done(10, 20);
|
|
});
|
|
runner.futures[0].execute(function(error, result) {
|
|
expect(error).toEqual(10);
|
|
expect(result).toEqual(20);
|
|
});
|
|
});
|
|
|
|
it('should execute spec function and notify UI', function() {
|
|
var finished;
|
|
var spec = createSpec('test spec', function() {
|
|
this.test = 'some value';
|
|
});
|
|
runner.addFuture('test future', function(done) {
|
|
done();
|
|
});
|
|
runner.run(spec, function() {
|
|
finished = true;
|
|
});
|
|
expect(runner.test).toEqual('some value');
|
|
expect(finished).toBeTruthy();
|
|
expect(log).toEqual([
|
|
'SpecBegin',
|
|
'StepBegin',
|
|
'StepEnd',
|
|
'SpecEnd'
|
|
]);
|
|
});
|
|
|
|
it('should execute notify UI on spec setup error', function() {
|
|
var finished;
|
|
var spec = createSpec('test spec', function() {
|
|
throw 'message';
|
|
});
|
|
runner.run(spec, function() {
|
|
finished = true;
|
|
});
|
|
expect(finished).toBeTruthy();
|
|
expect(log).toEqual([
|
|
'SpecBegin',
|
|
'SpecError',
|
|
'SpecEnd'
|
|
]);
|
|
});
|
|
|
|
it('should execute notify UI on step failure', function() {
|
|
var finished;
|
|
var spec = createSpec('test spec');
|
|
runner.addFuture('test future', function(done) {
|
|
done('failure message');
|
|
});
|
|
runner.run(spec, function() {
|
|
finished = true;
|
|
});
|
|
expect(finished).toBeTruthy();
|
|
expect(log).toEqual([
|
|
'SpecBegin',
|
|
'StepBegin',
|
|
'StepFailure',
|
|
'StepEnd',
|
|
'SpecEnd'
|
|
]);
|
|
});
|
|
|
|
it('should execute notify UI on step error', function() {
|
|
var finished;
|
|
var spec = createSpec('test spec', function() {
|
|
this.addFuture('test future', function(done) {
|
|
throw 'error message';
|
|
});
|
|
});
|
|
runner.run(spec, function() {
|
|
finished = true;
|
|
});
|
|
expect(finished).toBeTruthy();
|
|
expect(log).toEqual([
|
|
'SpecBegin',
|
|
'StepBegin',
|
|
'StepError',
|
|
'StepEnd',
|
|
'SpecEnd'
|
|
]);
|
|
});
|
|
|
|
it('should run after handlers even if error in body of spec', function() {
|
|
var finished, after;
|
|
var spec = createSpec('test spec', function() {
|
|
this.addFuture('body', function(done) {
|
|
throw 'error message';
|
|
});
|
|
});
|
|
spec.after = function() {
|
|
this.addFuture('after', function(done) {
|
|
after = true;
|
|
done();
|
|
});
|
|
};
|
|
runner.run(spec, function() {
|
|
finished = true;
|
|
});
|
|
expect(finished).toBeTruthy();
|
|
expect(after).toBeTruthy();
|
|
expect(log).toEqual([
|
|
'SpecBegin',
|
|
'StepBegin',
|
|
'StepError',
|
|
'StepEnd',
|
|
'StepBegin',
|
|
'StepEnd',
|
|
'SpecEnd'
|
|
]);
|
|
});
|
|
|
|
});
|