jax
jax

Reputation: 38593

Access model from acceptance test

How do I access the current model? I am aware of application.__container_.lookup but I understand this is a bit of a hack.

import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'myapp/tests/helpers/start-app';

let application;

module('Acceptance | booking/edit', {
  beforeEach: function() {
    application = startApp();
  },

  afterEach: function() {
    Ember.run(application, 'destroy');
  }
});

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

  //At this point I would like to access the model returned from the route model hook.

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

Sample Route excerpt.

  this.route('booking', { path:'/booking' }, function() {
    this.route('edit', { path:'/:booking_id' }, function() {
      this.route('account', { path:'/account' });

      ...
    });

   ...
  });

Upvotes: 2

Views: 664

Answers (1)

Billybonks
Billybonks

Reputation: 1568

You should be able to use moduleFor and then within the test you can use this.subject() to access the controller.

moduleFor('controller:bookingsEdit', 'Bookings Edit Controller');

If moduleFor is undefined. Then import moduleFor import {moduleFor} from 'ember-qunit'; and then within the test you can use this.subject() to access the controller

moduleFor(fullName [, description [, callbacks]])

fullName: (String) - The full name of the unit, ie controller:application, route:index.

description: (String) optional - The description of the module

callbacks: (Object) optional - Normal QUnit callbacks (setup and teardown), with addition to needs, which allows you specify the other units the tests will need.

http://guides.emberjs.com/v1.10.0/testing/testing-controllers/

https://github.com/rwjblue/ember-qunit

Upvotes: 1

Related Questions