Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"getModelPayload isProxy get add unwrap".w is not a function #196

Closed
dillonwelch opened this issue May 7, 2016 · 10 comments
Closed

"getModelPayload isProxy get add unwrap".w is not a function #196

dillonwelch opened this issue May 7, 2016 · 10 comments

Comments

@dillonwelch
Copy link
Contributor

Trying to run the following code in a component integration test:

  let accountSettings = make('account-settings'); // factory defined in tests/factories/account-settings.js
  mockQueryRecord('account-settings', {}).returns({model: accountSettings});

and am getting the error in the title. Looks like it's related to this line? Not sure what to do here.

Using ember-data-factory-guy version 2.5.3.

@danielspaniel
Copy link
Collaborator

can you provide more detail .. Need the model, the test, the factory .. etc .. can you put together a github repo that recreates this error ? it's way easier to diagnose and fix for me

@dillonwelch
Copy link
Contributor Author

// addon/models/account-settings.js
import DS from 'ember-data';

export default DS.Model.extend({
  menu_links: DS.attr(),
  email:      DS.attr('string')
});

// tests/factories/account-settings.js
import FactoryGuy from 'ember-data-factory-guy';

FactoryGuy.define('account-settings', {
  default: {
    menu_links: [
      { name: 'Cats', url: '/cats' },
      { name: 'Dogs', url: '/dogs', asterisk: false },
      { name: 'Cookies', url: '/cookies', asterisk: true },
      { name: 'Resources', url: '/resources', target: '_blank' }
    ],
    email:  '[email protected]'
  }
});

// addon/components/nav-bar.js
import Ember from 'ember';
import layout from '../templates/components/nav-bar';

const { getOwner } = Ember;

let navbarControllerHelper = {
  selector: 'header.navbar li.with_dropdown',
  open(e) {
    let $el;
    Ember.$(this.selector).removeClass('open');
    $el = Ember.$(e.target).closest('li').addClass('open');

    return false;
  },
  closeOthers() {
    return this.$els.removeClass('open');
  },
  init() {
    let nav = this;
    Ember.$(document.body).on(
      'click.nav_dropdowns',
      Ember.$.proxy(nav.closeOthers, nav)
    );
    this.$els = Ember.$(this.selector);
    this.$els.each(function() {
      return Ember.$(this).on(
        'click.nav_dropdowns', '> a', Ember.$.proxy(nav.open, nav)
      );
    });
  }
};

export default Ember.Component.extend({
  layout: layout,
  store:  Ember.inject.service(),
  init() {
    this._super(...arguments);

    this.set(
      'hamburger',
      this.get('store').queryRecord('hamburger', {})
    );
    this.set(
      'accountSettings',
      this.get('store').queryRecord('account-settings', {})
    );
    this.set(
      'navbar_url',
      getOwner(this).resolveRegistration('config:environment').APP.NAVBAR_URL
    );
  },
  didInsertElement() {
    navbarControllerHelper.init();
  }
});

// tests/integration/components/nav-bar-test.js
import Ember from 'ember';
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import startApp from '../../helpers/start-app';
import httpStubs from '../../helpers/http-stubs';
import Pretender from 'pretender';
import { make, mockQueryRecord } from 'ember-data-factory-guy';

let server;

var App, i18nSvc;
const { getOwner } = Ember;

moduleForComponent('nav-bar', 'Integration | Component | nav bar', {
  integration: true,
  beforeEach() {
    App = startApp();
    i18nSvc = this.container.lookup('service:i18n');
    server = new Pretender();
  },
  afterEach() {
    Ember.run(App, 'destroy');
    server.shutdown();
  }
});

test('it renders the Q-Apps logo header', function(assert) {
  let accountSettings = make('account-settings');
  mockQueryRecord('account-settings', {}).returns({model: accountSettings});
  // custom helper method that I'm trying to replace with FactoryGuy
  // httpStubs.stubAccountSettingsMenu(server, {data: null});
  httpStubs.stubHamburgerMenu(server, {data: null});

  this.render(hbs`{{nav-bar}}`);

  andThen(function() {
    assert.equal(
      $.trim(this.$('header h1 a').html()),
      i18nSvc.t('q-centrix-ember-components.navbar.qcentrix').string,
      'error rendering logo'
    );
  });
});

I think that should be the relevant parts. If you need more info to diagnose, let me know and I'll put together a test repo on Monday.

@danielspaniel
Copy link
Collaborator

danielspaniel commented May 7, 2016

can you open console in your browser ( where ember application is running ) and run this:

console.log([1,2,1].uniq())

and tell me what happens?

@dillonwelch
Copy link
Contributor Author

I get TypeError: [1,2,1].uniq is not a function

@danielspaniel
Copy link
Collaborator

ok .. the problem then is that you don't have prototype extensions enabled and the "".w() is a String.prototype exension from ember.
https://guides.emberjs.com/v2.3.0/configuring-ember/disabling-prototype-extensions/
So, I will have to stop doing "".w()
I will publish new version and let you know when it's ready to try, which will get you past this error at least.

@dillonwelch
Copy link
Contributor Author

Ahhhhhh that explains it.

This is for an addon and I have ember-disable-prototype-extensions installed, which disables prototype extensions :)

@danielspaniel
Copy link
Collaborator

danielspaniel commented May 9, 2016

can you try the new version 2.5.4 ? I removed all the .w()'s .. and I hope that is all that is needed for this to work.

Actually .. hold on .. need to fix more code that is using prototype extensions.

@danielspaniel
Copy link
Collaborator

Ok this time I installed that addon and caught a slew of other places I needed to fix. Now, version 2.5.5 is all set.

@dillonwelch
Copy link
Contributor Author

Works for me, thanks! 👍

@danielspaniel
Copy link
Collaborator

Awesome .. case closed. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants