Guest User

Untitled

a guest
Jul 22nd, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Ember from 'ember';
  2. import { test, moduleFor } from 'ember-qunit';
  3. import run from 'ember-runloop';
  4. const { getOwner } = Ember;
  5.  
  6. let store;
  7.  
  8. moduleFor('serializer:note', {
  9.   integration: true,
  10.   beforeEach() {
  11.     store = getOwner(this).lookup('service:store');
  12.   }
  13. });
  14.  
  15.  
  16.  
  17. test('#serialize', function(assert) {
  18.   assert.expect(1);
  19.  
  20.   let serializer = this.subject();
  21.   let note;
  22.  
  23.   run(() => {
  24.     note = store.createRecord('note', {
  25.       body: 'foo'
  26.     });
  27.   });
  28.  
  29.   let snapshot = note._createSnapshot();
  30.  
  31.   let json = serializer.serialize(snapshot);
  32.  
  33.   // Could do:
  34.   // let json = note.serialize()
  35.   // ...but that is a confusing indirect test
  36.  
  37.   assert.equal(json.content, 'foo',
  38.     "serializes a note's body into `content`");
  39. });
  40.  
  41.  
  42.  
  43. test('#normalize', function(assert) {
  44.   assert.expect(1);
  45.  
  46.   let serializer = this.subject();
  47.   let modelClass = store.modelFor('note');
  48.  
  49.   let resourceHash = { content: 'foo' };
  50.  
  51.   let json = serializer.normalize(modelClass, resourceHash);
  52.  
  53.   assert.equal(json.data.attributes.body, 'foo',
  54.     "a note's content is interpreted as `body`");
  55. });
Advertisement
Add Comment
Please, Sign In to add comment