admin管理员组文章数量:1405585
On the Jasmine website I see that we can disable suites by xdescribe
or individual specs by xit
. Is there a way to disable only an expectation (like xexpect
)?
The reason why I'm asking this is because I'm writing e2e tests with Protractor and in our continuous integration we don't yet (if ever) have access to the database, though locally we can run real end to end tests with access to the database, for example.
I would like to mark individual expectations as optional, depending on a configuration or environment variable. It would be nice to make a switch once, and then create a wrapper around expect, that only fails if we are running the tests locally (with access to the database).
So for example I can create a new spec family:
if (process.env.DB_AVAILABLE) {
dbit = it;
} else {
dbit = xit;
}
and write specs that depend on database connection as following:
dbit('creates new user', function () {});
Is there a way to do the same with expect
(e.g. dbexpect
)?
If there is something fundamentally wrong with my approach, don't hold it back and let me know.
On the Jasmine website I see that we can disable suites by xdescribe
or individual specs by xit
. Is there a way to disable only an expectation (like xexpect
)?
The reason why I'm asking this is because I'm writing e2e tests with Protractor and in our continuous integration we don't yet (if ever) have access to the database, though locally we can run real end to end tests with access to the database, for example.
I would like to mark individual expectations as optional, depending on a configuration or environment variable. It would be nice to make a switch once, and then create a wrapper around expect, that only fails if we are running the tests locally (with access to the database).
So for example I can create a new spec family:
if (process.env.DB_AVAILABLE) {
dbit = it;
} else {
dbit = xit;
}
and write specs that depend on database connection as following:
dbit('creates new user', function () {});
Is there a way to do the same with expect
(e.g. dbexpect
)?
If there is something fundamentally wrong with my approach, don't hold it back and let me know.
Share Improve this question asked Jul 5, 2016 at 16:40 Vince VargaVince Varga 6,9788 gold badges53 silver badges63 bronze badges 4-
Not sure about prepending it to the
expect
statement -- but you could possibly usebrowser.getProcessedConfig()
and check theseleniumAddress
and do conditionalexpect
's (assuming you have 2 configs, one for local and one for the CI server).if(local) { expect(true).toBe(true) } else { expect(false).toBe(false) }
... but this might be costly if you are doing it in a lot of places. – Gunderson Commented Jul 5, 2016 at 17:03 -
Also I never even thought about changing the
it
to a variable based on environment... thanks for that :) – Gunderson Commented Jul 5, 2016 at 17:06 - Thank you. Yes, I thought about it, but was looking for a clean solution – Vince Varga Commented Jul 5, 2016 at 17:10
- We do not have such option in Jasmine, only way to do so is that either you have to maintain two different specs for each environment or use if conditions while writing spec based on environment variable – Optimworks Commented Jul 5, 2016 at 17:15
1 Answer
Reset to default 4You could create your own xexpect
by implementing all the methods/properties with an empty function:
var xexpect = function() {
return xexpect;
};
Object.getOwnPropertyNames(jasmine.Expectation.prototype).forEach(function(name){
xexpect[name] = xexpect;
});
Object.defineProperty(xexpect, 'not', {get: xexpect});
Usage :
xexpect(1).toBeGreaterThan(2);
xexpect(true).not.toEqual(true);
本文标签: javascriptDisable Jasmine expectationlike xdescribe or xitStack Overflow
版权声明:本文标题:javascript - Disable Jasmine expectation, like xdescribe or xit? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744333661a2601083.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论