mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Inject jquery into future scope, and rename outer scenario to _window, which is what it is
This commit is contained in:
parent
21d2b43e6c
commit
86c2ef87d5
5 changed files with 29 additions and 25 deletions
|
|
@ -5,7 +5,7 @@ angular.scenario.dsl.browser = {
|
|||
this.testFrame.load(function(){
|
||||
self.testFrame.unbind();
|
||||
self.testWindow = self.testFrame[0].contentWindow;
|
||||
self.testDocument = jQuery(self.testWindow.document);
|
||||
self.testDocument = self.jQuery(self.testWindow.document);
|
||||
self.$browser = self.testWindow.angular.service.$browser();
|
||||
self.notifyWhenNoOutstandingRequests =
|
||||
bind(self.$browser, self.$browser.notifyWhenNoOutstandingRequests);
|
||||
|
|
@ -53,17 +53,18 @@ angular.scenario.dsl.repeater = function(selector) {
|
|||
},
|
||||
collect: function() {
|
||||
return $scenario.addFuture(namePrefix + ' collect', function(done) {
|
||||
var self = this;
|
||||
var doCollect = bind(this, function() {
|
||||
var repeaterArray = [];
|
||||
this.testDocument.find(selector).each(function(index) {
|
||||
var element = angular.extend(_jQuery(this),
|
||||
var element = angular.extend(self.jQuery(this),
|
||||
{bindings: [],
|
||||
boundTo: function(name) { return this.bindings[name]; }}
|
||||
);
|
||||
element.find('*').each(function(index) {
|
||||
var bindName = _jQuery(this).attr('ng:bind');
|
||||
var bindName = self.jQuery(this).attr('ng:bind');
|
||||
if (bindName) {
|
||||
element.bindings[bindName] = _jQuery(this).text();
|
||||
element.bindings[bindName] = self.jQuery(this).text();
|
||||
}
|
||||
});
|
||||
repeaterArray[index] = element;
|
||||
|
|
@ -79,14 +80,15 @@ angular.scenario.dsl.repeater = function(selector) {
|
|||
angular.scenario.dsl.element = function(selector) {
|
||||
var nameSuffix = "element '" + selector + "'";
|
||||
return $scenario.addFuture('Find ' + nameSuffix, function(done) {
|
||||
var self = this;
|
||||
var element = angular.extend(this.testDocument.find(selector), {
|
||||
bindings: [],
|
||||
boundTo: function(name) { return this.bindings[name]; }
|
||||
});
|
||||
element.find('*').each(function(index) {
|
||||
var bindName = _jQuery(this).attr('ng:bind');
|
||||
var bindName = self.jQuery(this).attr('ng:bind');
|
||||
if (bindName) {
|
||||
element.bindings[bindName] = _jQuery(this).text();
|
||||
element.bindings[bindName] = self.jQuery(this).text();
|
||||
}
|
||||
});
|
||||
done(element);
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ angular.scenario.Runner.prototype = {
|
|||
},
|
||||
specThis = createScope({
|
||||
result: result,
|
||||
jQuery: this.jQuery,
|
||||
testFrame: this.testFrame,
|
||||
testWindow: this.testWindow
|
||||
}, angularService, {});
|
||||
|
|
|
|||
|
|
@ -5,15 +5,16 @@ describe("DSL", function() {
|
|||
beforeEach(function() {
|
||||
setUpContext();
|
||||
executeFuture = function(future, html, callback) {
|
||||
lastDocument =_jQuery('<div>' + html + '</div>');
|
||||
lastDocument = _jQuery('<div>' + html + '</div>');
|
||||
_jQuery(document.body).append(lastDocument);
|
||||
var specThis = {
|
||||
testWindow: window,
|
||||
testDocument: lastDocument
|
||||
testDocument: lastDocument,
|
||||
jQuery: _jQuery
|
||||
};
|
||||
future.behavior.call(specThis, callback || noop);
|
||||
};
|
||||
Expect = scenario.expect;
|
||||
Expect = _window.expect;
|
||||
});
|
||||
|
||||
describe("input", function() {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ describe('Runner', function() {
|
|||
|
||||
beforeEach(function() {
|
||||
setUpContext();
|
||||
Describe = scenario.describe;
|
||||
It = scenario.it;
|
||||
BeforeEach = scenario.beforeEach;
|
||||
AfterEach = scenario.afterEach;
|
||||
Describe = _window.describe;
|
||||
It = _window.it;
|
||||
BeforeEach = _window.beforeEach;
|
||||
AfterEach = _window.afterEach;
|
||||
body = _jQuery('<div></div>');
|
||||
});
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ describe('Runner', function() {
|
|||
});
|
||||
$scenario.run(body);
|
||||
expect(log).toEqual('future1;after;future2;after;');
|
||||
expect(scenario.$testrun.results).toEqual([
|
||||
expect(_window.$testrun.results).toEqual([
|
||||
{ name : 'describe name: it should text1',
|
||||
passed : false,
|
||||
error : 'AfterError',
|
||||
|
|
@ -186,7 +186,7 @@ describe('Runner', function() {
|
|||
expect(spec.result.failed).toEqual(true);
|
||||
expect(spec.result.finished).toEqual(true);
|
||||
expect(spec.result.error).toEqual("MyError");
|
||||
expect(scenario.$testrun.results).toEqual([{
|
||||
expect(_window.$testrun.results).toEqual([{
|
||||
name: 'spec',
|
||||
passed: false,
|
||||
error: 'MyError',
|
||||
|
|
@ -217,16 +217,16 @@ describe('Runner', function() {
|
|||
expect(log).toEqual('s1,s2,s3,s4,');
|
||||
});
|
||||
it('should publish done state and results as tests are run', function() {
|
||||
expect(scenario.$testrun.done).toBeFalsy();
|
||||
expect(scenario.$testrun.results).toEqual([]);
|
||||
expect(_window.$testrun.done).toBeFalsy();
|
||||
expect(_window.$testrun.results).toEqual([]);
|
||||
$scenario.run(body);
|
||||
expect(scenario.$testrun.done).toBeFalsy();
|
||||
expect(scenario.$testrun.results).toEqual([
|
||||
expect(_window.$testrun.done).toBeFalsy();
|
||||
expect(_window.$testrun.results).toEqual([
|
||||
{name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']}
|
||||
]);
|
||||
next();
|
||||
expect(scenario.$testrun.done).toBeTruthy();
|
||||
expect(scenario.$testrun.results).toEqual([
|
||||
expect(_window.$testrun.done).toBeTruthy();
|
||||
expect(_window.$testrun.results).toEqual([
|
||||
{name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']},
|
||||
{name: 'd1: it it2', passed: true, error: undefined, steps: ['s2', 's2.2']},
|
||||
{name: 'd2: it it3', passed: true, error: undefined, steps: ['s3']},
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
var scenario, runner, log, $scenario;
|
||||
var _window, runner, log, $scenario;
|
||||
|
||||
function logger(text) {
|
||||
return function(done){
|
||||
|
|
@ -8,8 +8,8 @@ function logger(text) {
|
|||
}
|
||||
|
||||
function setUpContext() {
|
||||
scenario = {};
|
||||
runner = new angular.scenario.Runner(scenario, _jQuery);
|
||||
$scenario = scenario.$scenario;
|
||||
_window = {};
|
||||
runner = new angular.scenario.Runner(_window, _jQuery);
|
||||
$scenario = _window.$scenario;
|
||||
log = '';
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue