Skip to content

Commit

Permalink
add ember-data tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Apr 14, 2019
1 parent 26bbe20 commit 2bd763e
Show file tree
Hide file tree
Showing 3 changed files with 417 additions and 17 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"ember-cli-sri": "^2.1.1",
"ember-cli-template-lint": "^1.0.0-beta.1",
"ember-cli-uglify": "^2.1.0",
"ember-data": "^3.9.0",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.1.0",
Expand Down
61 changes: 61 additions & 0 deletions tests/unit/data-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { module, test } from "qunit";
import DS from "ember-data";
import { getContext } from "@ember/test-helpers";
import { setupApplicationTest } from "ember-qunit";

function getService(name) {
return getContext().owner.lookup(`service:${name}`);
}

function register(registeredName, object) {
getContext().owner.register(registeredName, object);
}

function stubAdapter() {
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 expectedNames = [name1, name2].join();

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

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();

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

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();

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

0 comments on commit 2bd763e

Please sign in to comment.