Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Throw early error when invalid suite is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Tatarintsev committed May 19, 2014
1 parent 1ed1190 commit 463ec57
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
the same parent.
* Throw error when creating multiple states of the same name within
the suite.
* Throw error when creating suite that will be unable to run (
has states and hasn't url or capture region);
* Check argument types of `SuiteBuilder` methods.
* Check argument types of all actions methods.
* Shorter stacktraces for invalid elements errors.
Expand Down
13 changes: 13 additions & 0 deletions lib/tests-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ module.exports = function(context, rootSuite) {

rootSuite = Suite.create(name, rootSuite);
callback(new SuiteBuilder(rootSuite));
if (rootSuite.hasStates) {
if (!rootSuite.url) {
throw new Error('URL is required to capture screenshots. ' +
'Call suite.setUrl(<DESIRED PATH>) on "' + rootSuite.name +
'" suite or one of its parents');
}

if (!rootSuite.captureSelectors) {
throw new Error('Capture region is required to capture screenshots. ' +
'Call suite.setCaptureElements(<CSS SELECTORS>) on "' + rootSuite.name +
'" suite or one of its parents');
}
}
rootSuite = rootSuite.parent;
};
};
94 changes: 85 additions & 9 deletions test/tests-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,71 @@ describe('public tests API', function() {

this.suite.children[1].name.must.be('second');
});

it('should throw when suite has states but does not has URL', function() {
var _this = this;
(function() {
_this.context.suite('first', function(suite) {
suite.setCaptureElements('.element')
.capture('plain');
});
}.must.throw());
});

it('should throw when suite has no states nor URL', function() {
var _this = this;
(function() {
_this.context.suite('first', function(suite) {
suite.setCaptureElements('.element');
});
}.must.not.throw());
});

it('should not throw when suite has states and url is inherited from parent', function() {
var _this = this;
(function() {
_this.context.suite('first', function(suite) {
suite.setUrl('/url');
_this.context.suite('child', function(suite) {
suite.setCaptureElements('.element')
.capture('plain');
});
});
}.must.not.throw());
});

it('should throw if suite has states but does not has captureSelectors', function() {
var _this = this;
(function() {
_this.context.suite('first', function(suite) {
suite.setUrl('/url')
.capture('plain');
});
}.must.throw());
});

it('should not throw if suite has no states nor captureSelectors', function() {
var _this = this;
(function() {
_this.context.suite('first', function(suite) {
suite.setUrl('/url');
});
}.must.not.throw());
});

it('should not throw when suite has states and captureSelectors are inherited from parent', function() {
var _this = this;
(function() {
_this.context.suite('first', function(suite) {
suite.setCaptureElements('.element');
_this.context.suite('child', function(suite) {
suite.setUrl('/url')
.capture('plain');
});
});
}.must.not.throw());
});

});

describe('suite builder', function() {
Expand Down Expand Up @@ -156,33 +221,38 @@ describe('public tests API', function() {
});

describe('capture', function() {
function prepareSuite(suite) {
return suite.setUrl('/path')
.setCaptureElements('.element');
}

it('should throw if first argument is not passed', function() {
(function() {
this.context.suite('name', function(suite) {
suite.capture({not: 'a string'});
prepareSuite(suite).capture({not: 'a string'});
});
}.bind(this)).must.throw(TypeError);
});

it('should throw if second argument is not a function', function() {
(function() {
this.context.suite('name', function(suite) {
suite.capture('state', 'make me a sandwich');
prepareSuite(suite).capture('state', 'make me a sandwich');
});
}.bind(this)).must.throw(TypeError);
});

it('should not throw if second argument is absent', function() {
(function() {
this.context.suite('name', function(suite) {
suite.capture('state');
prepareSuite(suite).capture('state');
});
}.bind(this)).must.not.throw();
});

it('should create named state', function() {
this.context.suite('name', function(suite) {
suite.capture('state');
prepareSuite(suite).capture('state');
});

this.suite.children[0].states[0].name.must.equal('state');
Expand All @@ -200,8 +270,9 @@ describe('public tests API', function() {

it('should allow to have multiple states of different names', function() {
this.context.suite('name', function(suite) {
suite.capture('state 1');
suite.capture('state 2');
prepareSuite(suite)
.capture('state 1')
.capture('state 2');
});


Expand All @@ -211,7 +282,7 @@ describe('public tests API', function() {

it('should make new state reference the suite', function() {
this.context.suite('name', function(suite) {
suite.capture('state');
prepareSuite(suite).capture('state');
});

this.suite.children[0].states[0].suite.must.equal(this.suite.children[0]);
Expand All @@ -226,7 +297,7 @@ describe('public tests API', function() {
};

this.context.suite('name', function(suite) {
suite.capture('state', spy);
prepareSuite(suite).capture('state', spy);
});

this.suite.children[0].states[0].activate(browser, {});
Expand All @@ -235,7 +306,12 @@ describe('public tests API', function() {

});

shouldBeChainable('capture', 'state');
it('should be chainable', function(done) {
this.context.suite('name', function(suite) {
prepareSuite(suite).capture('state').must.be(suite);
done();
});
});
});

describe('skip', function() {
Expand Down

0 comments on commit 463ec57

Please sign in to comment.