javascript - Disable Jasmine expectation, like xdescribe or xit? - Stack Overflow

On the Jasmine website I see that we can disable suites by xdescribe or individual specs by xit. Is the

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 use browser.getProcessedConfig() and check the seleniumAddress and do conditional expect'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
Add a ment  | 

1 Answer 1

Reset to default 4

You 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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744333663a4569008.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信