0

Ember serializer test below is failing with “Cannot read property ‘push’ of null”.

I am using Pretender mock server library. The test is failing when I'm calling a store.findRecord()

Note how there are no relationships in the assignment model/serializer, which is why it's confusing that it's throwing the following error:

Click here to see the error that's getting returned

assignment serializer:

import DS from 'ember-data';
const { JSONAPISerializer } = DS;

export default JSONAPISerializer.extend({
attrs: {
    autoPassReviewerNote: 'autoPassReviewerNote',
        dateOfCreation: 'date_of_creation',
        displayType: 'displayType',
        lastUpdate: 'last_update',
        moduleItem: 'moduleItem',
        submissionType: 'submissionType'
    }
});

assignment model:

import DS from 'ember-data';
const {
    Model,
    attr
} = DS;

    export default Model.extend({
    title: attr('string'),
    submissionType: attr('string'),
    description: attr('string'),
    completed: attr('boolean'),
    displayType: attr('string'),
    dateOfCreation: attr('string'),
    lastUpdate: attr('string'),
    autopass: attr('boolean'),
    moduleItem: attr('object')
});

serializer test (which is failing):

import { moduleForModel, test } from 'ember-qunit';
import Pretender from 'pretender';
import Ember from 'ember';

const {
    run
} = Ember;

var server;

moduleForModel('assignment', 'Unit | Serializer | assignment', {
    needs: [
        'serializer:assignment'
    ],

    beforeEach: function() {
        server = new Pretender(function() {
            // eslint-disable-next-line ember/use-ember-get-and-set
            this.get('/assignments/:id', function() {
                    data: {
                        type: 'assignment',
                        id: 98,
                        attributes: {
                            title: 'dfgdfg',
                            submissionType: 'dfgdf',
                            displayType: 'dfgdfg',
                            date_of_creation: 'sdfgsdfg',
                            last_update: 'fgdgd'
                        }
                    }
                };

                return [ 200, { 'Content-Type': 'application/json' }, JSON.stringify(response) ];
            });
        });
    },

    afterEach: function() {
        server.shutdown();
    }
});

test('testing assignment serializer', function(assert) {
    var checkAttrSerialization = (assignment) => {
        assert.equal(assignment, true);
    }

    let store = this.store();

    run(() => {
        return store.findRecord('assignment', 98).then((assignment) => checkAttrSerialization(assignment));
    });
});
  • 1) please add note about versions 2) I can find neither `_pushInternalModel` nor `_setupRelationshipsForModel` at origingal `ember-data` repo -- is it your methods? if yes - give their code – Vasiliy vvscode Vanchuk Aug 02 '17 at 06:29
  • Hi Vasily- `_pushInternalModel` and `_setupRelationshipsForModel` are under-the-hood Ember methods according to the stack trace- Ember is trying to push the serialized data to the model. Interestingly, even when I remove all of the relationships of `assignment` on both the model and the serializer, this error is still thrown. So I don't think the error is related to the relationships of this particular payload. – David Zernik Aug 02 '17 at 19:13
  • Did you find a solution for this? I have the same problem and getting out of ideas... – jvenezia Nov 17 '17 at 00:44

0 Answers0