Mocha and tea transporter

I started using the Transporter and the first thing I tried to do was use Urine and Tea, not Jasmine. Although now I'm not sure if that was a good idea.

First I needed to make Chai available from all spec files, without having to import each time, I found that this can be done in the protractor.conf file:

  onPrepare: ->
      global.chai = require 'chai'
      chai.use require 'chai-string'
      chai.use require 'chai-as-promised'
      global.expect = chai.expect

      

now the spec is like this:

  it "when clicked should sort ",->
      headerColumns.get(0).click()
      firstCellText = $$(".first-cell").getText()
      secondCellText = $$(".second-cell").getText()

      # this won't work
      expect(firstCellText).eventually.be.above(secondCellText)             

      

to make it work, I could do:

    # now this works
    $$(".second-cell").getText().then (secondCellText)->
        expect(firstCellText).eventually.be.above(secondCellText)             

      

but it's ugly and I don't want to constantly wrap the content inside .then

. I think there must be a better way (?)

+3


source to share


3 answers


I had the same problem. The problem for me was to add a longer timeout to the mocha via the Protractor config.js configurator.

This works because Protractor tests take significantly longer than other modules, such as supertest, that the actual browser interacts with.

I added



  mochaOpts: {
   timeout: 5000
  }

      

to my transporter config and passed tests.

+2


source


I found this question while I was trying to do the same in TypeScript, but the approach is protractor.conf.js

identical.

Creation of chai on a global scale

It looks like you have achieved this, you are correct that it needs to be done in preparation. below is an example. As far as I understand, this is necessary because tea is of course no different from mocha, but some additional candies that we can use with mocha. Unlike jasmine, where everything is included in the structure.

snippet protractor.conf.js

onPrepare: function() {
  var chai = require('chai'); // chai
  var chaiAsPromised = require("chai-as-promised"); // deal with promises from protractor
  chai.use(chaiAsPromised); // add promise candy to the candy of chai
  global.chai = chai; // expose chai globally
}

      

example spec

Once you have purchased chai and chai-as-promised customization worldwide, you need to add a "small" boiler plate to your spec to expose expect

that comes from chai.

example.e2e-spec.ts snippet



const expect = global['chai'].expect; // obviously TypeScript


it('will display its title', () => {
  pageObject.navigateTo();

  const title = element(by.css('app-root h1')).getText();
  expect(title).to.eventually.contain('An awesome title');
});

      

Avoid

I can not tell what your links $$

, but if you use the components transportiratora browser

and by

etc, then all the little pochischaetsya.

The call const title = element(by.css('app-root h1')).getText();

seems to return the promise, which Jasmine appears to be dealing with a box while mocha + tea does not. What happens in someone's promise.

using our extra syntax candy expect(title).to.eventually.contain('An awesome title');

, it removes the promise entirely and we avoided all those calls then

, but we need it eventually

.

I've provided you with a link to a working TypeScript example that might help you demonstrate.

I hope this helps someone who finds this old question.

0


source


Or, you need to specify a timeout for the whole test suite using "this.timeout (1000)"; just below the declaration block, or you can change it for individual test cases by explicitly defining a timeout for each "it" block.

example for block description :

describe("test-suite",function () {
    this.timeout(5000);
    it("test-case",function () {
       //test case code goes here 
    });
});

      

example for block :

it("test-case",function () {
        this.timeout("20000");
    });

      

0


source







All Articles