Skip to content

Instantly share code, notes, and snippets.

@twokul
Created June 2, 2015 06:41
Show Gist options
  • Save twokul/c05450de4976b0487b4a to your computer and use it in GitHub Desktop.
Save twokul/c05450de4976b0487b4a to your computer and use it in GitHub Desktop.
ember-data-factory-guy-unit-test.js
import Ember from 'ember';
import { test } from 'ember-qunit';
import { moduleForComponent } from '../../helpers/ember-qunit';
import { build } from "../../helpers/factory-guy";
const run = Ember.run;
moduleForComponent('user-info-component', {
integration: true,
subject(options, factory) {
return factory.create(options);
},
store() {
return this.container.lookup('store:main');
},
getUserInfo(attributes) {
const payload = build('user', attributes);
const store = this.context.store();
run(function() {
store.pushPayload('user', { user: payload });
});
return store.getById('user', payload.id);
},
});
test('it shows the details for a user', function(assert) {
assert.expect(2);
const user = this.getUserInfo({
first_name: 'David',
last_name: 'Hamilton'
});
const component = this.subject({ user: user });
this.render();
const firstName = component.$('.first-name');
const lastName = component.$('.last-name');
assert.equal(firstName.text(), 'David', 'first name is correct');
assert.equal(lastName.text(), 'Hamilton', 'last name is correct');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment