Problems with async test written in babel


#1

This is probably me doing a WTF, but I’m trying to update some tests of somebody else’s package that is written with babel. When adding waitForPromise calls it just breaks and I don’t understand why. I’ve minified it to this:

Works in coffeescript:

describe 'javascript-processor (coffee)', ->
  beforeEach ->
    waitsForPromise ->
      atom.workspace.open('sample2.js').then( (e) -> editor = e)

  describe 'method', ->
    it 'should have waited long enough', ->
      expect(true)

Borked with babel:

'use babel';
describe('javascript-processor (babel)', function() {
  let editor = null;

  beforeEach(function() {
    waitsForPromise(function() {
      atom.workspace.open('sample2.js').then(function(e) {
        editor = e;
      });
    });
  });

  describe('method', function() {
    it('should have waited long enough', function() {
      expect(true);
    });
  });
});

The later gives me
TypeError: Cannot read property ‘then’ of undefined
at /Applications/Atom.app/Contents/Resources/app.asar/spec/spec-helper.js:488:16

and
timeout: timed out after 5000 msec waiting for something to happen


#2

You should return the promise in the waitsForPromise callback: return atom.workspace.open(...). Coffeescript does this automatically for you, by returning the last expression in a function.


#3

Of course! Thanks!