adopted-ember-addons/ember-data-factory-guy

manualSetup in beforeEach hook error on rest adapter ajax method.

arenoir opened this issue · 5 comments

I am working on upgrading my application from ember 2.18 lts to 3.4 lts.

It appears that the manualSetup hook is failing to setup the store.

I am receiving the following error on the ember-data rest adapter:

    rest.js:893 Uncaught TypeError: Cannot read property 'ajax' of undefined
    at Class._ajaxRequest (rest.js:893)

Any help is greatly appreciated.

ember-cli ~3.4
ember-source: ~3.4
ember-data: ~3.4
ember-data-factory-guy tried both [~3.3, ~3.4]

are you on
"ember-ajax": "^3.1.2",

hard to fix this kind of thing because i am on 3.4 everything ( same as you are ) and it all works fine .. meaning the issue is one of your other packages ( like ember-ajax would be obvious first guess ) but there might be others that need updating ?? not sure

but you might not have jquery install either .. cause the $.ajax is from jquery

Hey thanks for getting back to me. I am not sure what is going on but it is definitely not importing jquery. I used the ember-cli-upgrade tool and it updated my ember-ajax to the correct version. I am in a clean node 10 environment using nvm. I have overridden the adapter to test and it is not importing jquery. So it must be an environment issue.

# app/adapters/application.js
import $ from 'jquery';
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  _ajaxRequest(options) {
    console.log('wtf')
    console.log($);
    return $.ajax(options);
  }
});

#console prints 
application.js:16 wtf
application.js:17 undefined
#tests/unit/models/address.js

import {
  mockCreate,
  setupFactoryGuy,
  manualSetup
} from 'ember-data-factory-guy';

module('Unit | Model | address', function(hooks) {
  setupTest(hooks);
  //setupFactoryGuy(hooks);
  hooks.beforeEach(function(assert) {
    manualSetup(this);
    //throw new Error('halt');
  });
  test('creating a new address that returns an existing record works', function(assert) {
    assert.expect(2);
    let attrs = {
      id: 10,
      lineOne: 'some line one',
      city: 'Oakland',
      state: 'Ca',
      zip: '94609'
    }

    mockCreate('address').returns({attrs: attrs});

that is not a factory guy issue .. so i wonder how I can help?

Thanks @danielspaniel I guess I missed it but I had to install ember-jquery and enable optional features.

ember install @ember/jquery
ember install @ember/optional-features
ember feature:enable jquery-integration

Thanks @danielspaniel I guess I missed it but I had to install ember-jquery and enable optional features.

ember install @ember/jquery
ember install @ember/optional-features
ember feature:enable jquery-integration

Thanks a lot )