mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-06 12:44:28 +02:00
more test DSL
This commit is contained in:
parent
8709f87b4f
commit
27ec708cc2
2 changed files with 52 additions and 18 deletions
|
@ -15,6 +15,44 @@ var CasperUtils = {
|
||||||
return this.getUrl() + '&command=' + commands.join(';');
|
return this.getUrl() + '&command=' + commands.join(';');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testDone: function() {
|
||||||
|
this.test.done();
|
||||||
|
},
|
||||||
|
|
||||||
|
multiAssert: function() {
|
||||||
|
// Copy the args into a variable we can reference inside
|
||||||
|
// our closure.
|
||||||
|
var asserts = [];
|
||||||
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
|
asserts.push(arguments[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return function then() {
|
||||||
|
for (var i = 0; i < asserts.length; i++) {
|
||||||
|
var assert = asserts[i];
|
||||||
|
assert.bind(this)();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
asserts: {
|
||||||
|
visibleIDs: function(visibleIDs) {
|
||||||
|
return function then() {
|
||||||
|
visibleIDs.forEach(function(id) {
|
||||||
|
this.test.assertVisible('#' + id);
|
||||||
|
}.bind(this));
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
visibleSelectors: function(selectors) {
|
||||||
|
return function then() {
|
||||||
|
selectors.forEach(function(selector) {
|
||||||
|
this.test.assertExists(selector);
|
||||||
|
}.bind(this));
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
waits: {
|
waits: {
|
||||||
jsMount: function() {
|
jsMount: function() {
|
||||||
return this.evaluate(function() {
|
return this.evaluate(function() {
|
||||||
|
|
|
@ -24,25 +24,21 @@ casper.start(
|
||||||
function() {
|
function() {
|
||||||
this.test.assertTitle('Learn Git Branching');
|
this.test.assertTitle('Learn Git Branching');
|
||||||
|
|
||||||
casper.waitFor(CasperUtils.waits.jsMount, function then() {
|
casper.waitFor(
|
||||||
visibleIDs.forEach(function(id) {
|
CasperUtils.waits.jsMount
|
||||||
this.test.assertVisible('#' + id);
|
)
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
selectors.forEach(function(selector) {
|
.then(CasperUtils.multiAssert(
|
||||||
this.test.assertExists(selector);
|
CasperUtils.asserts.visibleIDs(visibleIDs),
|
||||||
}.bind(this));
|
CasperUtils.asserts.visibleSelectors(selectors)
|
||||||
|
))
|
||||||
|
|
||||||
})
|
.waitFor(CasperUtils.waits.allCommandsFinished)
|
||||||
.waitFor(CasperUtils.waits.allCommandsFinished, function then() {
|
|
||||||
doneSelectors.forEach(function(selector) {
|
|
||||||
this.test.assertExists(selector);
|
|
||||||
}.bind(this));
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
this.test.done();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
.then(
|
||||||
|
CasperUtils.asserts.visibleSelectors(doneSelectors)
|
||||||
|
)
|
||||||
|
|
||||||
casper.run();
|
.then(CasperUtils.testDone);
|
||||||
|
|
||||||
|
}).run();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue