Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Garrett committed Apr 18, 2019
1 parent 9d8771e commit e61012e
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions tests/unit/data-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { module, test } from "qunit";
import DS from "ember-data";
import { getContext } from "@ember/test-helpers";
import { setupApplicationTest } from "ember-qunit";
import { module, test } from 'qunit';
import DS from 'ember-data';
import { getContext } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { get as emberGet } from '@ember/object';
import { gte } from 'ember-compatibility-helpers';

function get(obj, key) {
if (gte('3.1.0')) {
return obj[key];
} else {
return emberGet(obj, key);
}
}

function getService(name) {
return getContext().owner.lookup(`service:${name}`);
Expand All @@ -12,50 +22,48 @@ function register(registeredName, object) {
}

function stubAdapter() {
let store = getService("store");
let store = getService('store');
store.createRecord('post', { name: name1 });
store.createRecord('post', { name: name2 });
}

let name1 = "Rails is omakase";
let name2 = "The Parley Letter";
let name1 = 'Rails is omakase';
let name2 = 'The Parley Letter';
let expectedNames = [name1, name2].join();

module("ember-data", function(hooks) {
module('ember-data', function(hooks) {
setupApplicationTest(hooks);

test("attr", async function(assert) {
test('attr', async function(assert) {
let Post = DS.Model.extend({ name: DS.attr() });
register(`model:post`, Post);
stubAdapter();

let store = getService("store");
let posts = await store.peekAll("post");
let names = posts.toArray().map(post => post.name).join();
let store = getService('store');
let posts = await store.peekAll('post');
let names = posts
.toArray()
.map(post => get(post, 'name'))
.join();

assert.equal(
names,
expectedNames,
"The correct records are in the array"
);
assert.equal(names, expectedNames, 'The correct records are in the array');
});

test("@attr", async function(assert) {
test('@attr', async function(assert) {
let Post = class extends DS.Model {
@DS.attr() name;
}
};

register(`model:post`, Post);
stubAdapter();

let store = getService("store");
let posts = await store.peekAll("post");
let names = posts.toArray().map(post => post.name).join();
let store = getService('store');
let posts = await store.peekAll('post');
let names = posts
.toArray()
.map(post => get(post, 'name'))
.join();

assert.equal(
names,
expectedNames,
"The correct records are in the array"
);
assert.equal(names, expectedNames, 'The correct records are in the array');
});
});

0 comments on commit e61012e

Please sign in to comment.