ReferenceError: andThen is not defined

Hello,

I am just starting to learn Ember and currently running through the Tutorial. The guide is very clear and precisely explaining the concepts. However, I am unable to run the acceptance tests following the guide since the test runner is complaining about ‘andThen’ not being defined.

import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';

module('Acceptance | list rentals', function(hooks) {
    setupApplicationTest(hooks);

    test('visiting /', function(assert) {
        visit('/');

        andThen(function() {
            assert.equal(currentURL(), '/');
        });
    });
});

The tests fail throwing the following:

at requireModule (http://localhost:7357/assets/vendor.js:30:18)
 at TestLoader.require (http://localhost:7357/assets/test-support.js:10151:9): andT
        hen is not defined
                ReferenceError: andThen is not defined
                    at Object.<anonymous> (http://localhost:7357/assets/tests.js:12:13)
                    at runTest (http://localhost:7357/assets/test-support.js:4143:30)
                    at Test.run (http://localhost:7357/assets/test-support.js:4129:6)
                    at http://localhost:7357/assets/test-support.js:4335:12
                    at Object.advance (http://localhost:7357/assets/test-support.js:3781:26)
                    at begin (http://localhost:7357/assets/test-support.js:5724:20)
                    at http://localhost:7357/assets/test-support.js:4722:6
        ESLint | tests: acceptance/list-rentals-test.js
        ✘ acceptance/list-rentals-test.js should pass ESLint
    
    11:9 - 'andThen' is not defined. (no-undef)
            at Object.<anonymous> (http://localhost:7357/assets/tests.js:93:12)
            at runTest (http://localhost:7357/assets/test-support.js:4143:30)
            at Test.run (http://localhost:7357/assets/test-support.js:4129:6)
            at http://localhost:7357/assets/test-support.js:4335:12
            at Object.advance (http://localhost:7357/assets/test-support.js:3781:26)
            at begin (http://localhost:7357/assets/test-support.js:5724:20)
         expected true

package.json

{
  "name": "super-rentals",
  "version": "0.0.0",
  "private": true,
  "description": "Small description for super-rentals goes here",
  "license": "MIT",
  "author": "",
  "directories": {
    "doc": "doc",
    "test": "tests"
  },
  "repository": "",
  "scripts": {
    "build": "ember build",
    "lint:js": "eslint ./*.js app config lib server tests",
    "start": "ember serve",
    "test": "ember test"
  },
  "devDependencies": {
    "broccoli-asset-rev": "^2.4.5",
    "ember-ajax": "^3.0.0",
    "ember-cli": "~3.0.0",
    "ember-cli-app-version": "^3.0.0",
    "ember-cli-babel": "^6.6.0",
    "ember-cli-dependency-checker": "^2.0.0",
    "ember-cli-eslint": "^4.2.1",
    "ember-cli-htmlbars": "^2.0.1",
    "ember-cli-htmlbars-inline-precompile": "^1.0.0",
    "ember-cli-inject-live-reload": "^1.4.1",
    "ember-cli-qunit": "^4.1.1",
    "ember-cli-shims": "^1.2.0",
    "ember-cli-sri": "^2.1.0",
    "ember-cli-uglify": "^2.0.0",
    "ember-data": "~3.0.0",
    "ember-export-application-global": "^2.0.0",
    "ember-load-initializers": "^1.0.0",
    "ember-maybe-import-regenerator": "^0.1.6",
    "ember-resolver": "^4.0.0",
    "ember-source": "~3.0.0",
    "ember-welcome-page": "^3.0.0",
    "eslint-plugin-ember": "^5.0.0",
    "loader.js": "^4.2.3"
  },
  "engines": {
    "node": "^4.5 || 6.* || >= 7.*"
  }
}

Any pointers of where I am going wrong is appreciated.

Also, the code at GitHub - ember-learn/super-rentals: Codebase for the Super Rentals official tutorial doesn’t seem to be updated for Ember 3.0.

The testing system just changed in 3.0 so some of the docs are very different between 2.18 and 3.0. I think in this case you’d want to make sure you import “andThen” from the test helpers, like this:

import { visit, currentURL, andThen } from '@ember/test-helpers';

Oh I should also mention that in 3.0 I believe the preferred way is to use async/await rather than andThen, hence why andThen doesn’t seem to be mentioned in the guide anymore.

Thank you for the response. I had tried importing ‘andThen’ like you suggested, didn’t work. Also, it is not listed in https://github.com/emberjs/ember-test-helpers/blob/master/API.md as a helper.

Cound’t find any documentation about the usage of async/await till now (I am at ‘Using Ember Data’ section of the tutorial). Will read through the documentation to learn about using async/await.

Thanks again.

Ah yeah, when I upgraded to 3.0 I kept all my old test helper stuff around (until I change all my tests over to async/await) so it could be that andThen is being imported somewhere in there. If you’re starting with 3.0 though I’d definitely just try to learn the async/await method as that will be the standard going forward. Good luck!