BACKGROUND
In the RFC-232 , RFC-268 style tests we wanted to simplify some of the abstractions around testing, so it is simpler to implement, and the ecosystem gets out of the way more. This led to a paradigm shift from "I'm doing an x-style test", to "I'm testing X and need Y and Z configured in order to do it". E.g moduleForComponent
-> setupRenderingTest
, moduleForAcceptance
-> setupApplicationTest
.
In implementing the new style blueprints for ember-data, I'd like to understand where we'd like the ember-data testing story to go, and if this is the right point to do so, since we will be modifying those files.
As such, what are analagous concepts we could introduce for ember-data? Does it make sense to introduce these analagous concepts?
Ember Data Classes Who's Testing Use Cases We Need To Ensure We Address
- Adapters, Models, Serializers, Transforms
Classes who's testing style is addressed by APIs provided by ember-qunit
- Transforms ->
setupTest
(testing these has no dependency on ember or ember-data internals, similar to helpers)
Classes who's testing style needs to be discussed:
- Adapters
- Models
- Serializers
Adapters
Most adapater methods operate on snapshots. Should we provide an API to create snapshots from models, since models are the public API users are used to?
Internal models required for implementing/testing public methods: Snapshot
and SnapshotRecordArray
Models
When testing models, it's mostly about testing user computed properties. In which the user needs to setup the store
.
Serializers
Should we bootstrap the store onto this.store
for testing? Example implementation
function setupStoreTest(hooks) {
setupTest(hooks); // sets up container/owner
hooks.beforeEach(function() {
this.store = this.owner.lookup('service:store');
});
hooks.beforeEach(function() {
this.store = null;
});
};
JSONSerializer.serialze* methods
serialize(snapshot, json)
JSONSerializer.serialze* methods
serializeAttribute(snapshot, json, key, attribute)
serializeBelongsTo(snapshot, json, relationship)
serializeHasMany(snapshot, json, relationship)
serializeId(snapshot, json, primaryKey)
serializeIntoHash(hash, typeClass, snapshot, options)
serializePolymorphicType(snapshot, json, relationship)
shouldSerializeHasMany(snapshot, key, relationshipType)
All the serialze methods require a snapshot. Should we prove a testing API that can create these snapshots?
// this is an example of a explicit test setup
// we could imagine an "needs" based setup method would be called `setupSnapshotTest` for example
setupSerializerTest(hooks); // this hypothetical API adds `this.createSnapshot`
test('my-model -- serializeId', function(assert) {
let model = this.store.createRecord('my-model');
let snapshot = this.createSnapshot(model);
});
https://github.com/bmac/serializer-testing/blob/master/tests/unit/serializers/application-test.js#L59-L98