Skip to content

TypeError: Cannot read property 'some' of undefinedΒ #203

@knownasilya

Description

@knownasilya
 ERR ./tests/integration/components/tag-input-test.js Transformation error (Cannot read property 'some' of undefined)
TypeError: Cannot read property 'some' of undefined
    at new ModuleInfo (/Users/ilya/.npm/_npx/26337/lib/node_modules/ember-qunit-codemod/transforms/convert-module-for-to-setup-test/index.js:62:49)
    at createModule (/Users/ilya/.npm/_npx/26337/lib/node_modules/ember-qunit-codemod/transforms/convert-module-for-to-setup-test/index.js:330:24)
    at NodePath.bodyPath.each.expressionPath (/Users/ilya/.npm/_npx/26337/lib/node_modules/ember-qunit-codemod/transforms/convert-module-for-to-setup-test/index.js:700:28)
    at NodePath.each (/Users/ilya/.npm/_npx/26337/lib/node_modules/ember-qunit-codemod/node_modules/ast-types/lib/path.js:101:26)
    at processBody (/Users/ilya/.npm/_npx/26337/lib/node_modules/ember-qunit-codemod/transforms/convert-module-for-to-setup-test/index.js:697:16)
    at updateModuleForToNestedModule (/Users/ilya/.npm/_npx/26337/lib/node_modules/ember-qunit-codemod/transforms/convert-module-for-to-setup-test/index.js:748:5)
    at module.exports (/Users/ilya/.npm/_npx/26337/lib/node_modules/ember-qunit-codemod/transforms/convert-module-for-to-setup-test/index.js:974:3)

Code is (from https://github.com/calvinlough/ember-tag-input)

import { run, next } from '@ember/runloop';
import { A } from '@ember/array';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { typeInInput, typeCharacterInInput } from '../../helpers/ember-tag-input';

const KEY_CODES = {
  BACKSPACE: 8
};

module('tag-input', 'Integration | Component | Ember Tag Input', function(hooks) {
  setupRenderingTest(hooks);

  test('New tags are created when delimiter characters are typed', async function(assert) {
    assert.expect(4);

    const tags = A();

    this.addTag = function(tag) {
      tags.pushObject(tag);
    };
    this.set('tags', tags);

    await render(hbs`
      {{#tag-input
        tags=tags
        addTag=(action addTag)
        as |tag|
      }}
        {{tag}}
      {{/tag-input}}
    `);

    const done = assert.async();

    run(() => {
      typeInInput('.js-ember-tag-input-new', 'first second ');

      next(() => {
        assert.equal($('.js-ember-tag-input-new').text(), '');
        assert.equal($('.emberTagInput-tag').length, 2);
        assert.equal($('.emberTagInput-tag').eq(0).text().trim(), 'first');
        assert.equal($('.emberTagInput-tag').eq(1).text().trim(), 'second');
        done();
      });
    });
  });

  test('New tags are created when the field is blurred', async function(assert) {
    assert.expect(3);

    const tags = A();

    this.addTag = function(tag) {
      tags.pushObject(tag);
    };
    this.set('tags', tags);

    await render(hbs`
      {{#tag-input
        tags=tags
        addTag=(action addTag)
        as |tag|
      }}
        {{tag}}
      {{/tag-input}}
    `);

    const done = assert.async();

    run(() => {
      typeInInput('.js-ember-tag-input-new', 'blurry');

      $('.js-ember-tag-input-new').blur();

      next(() => {
        assert.equal($('.js-ember-tag-input-new').text(), '');
        assert.equal($('.emberTagInput-tag').length, 1);
        assert.equal($('.emberTagInput-tag').eq(0).text().trim(), 'blurry');
        done();
      });
    });
  });

  test('Tags can be removed using the backspace key', async function(assert) {
    assert.expect(5);

    const tags = A();

    this.addTag = function(tag) {
      tags.pushObject(tag);
    };
    this.removeTagAtIndex = function(index) {
      tags.removeAt(index);
    };
    this.set('tags', tags);

    await render(hbs`
      {{#tag-input
        tags=tags
        addTag=(action addTag)
        removeTagAtIndex=(action removeTagAtIndex)
        as |tag|
      }}
        {{tag}}
      {{/tag-input}}
    `);

    const done = assert.async();

    run(() => {
      typeInInput('.js-ember-tag-input-new', 'removeme ');

      next(() => {
        assert.equal($('.js-ember-tag-input-new').text(), '');
        assert.equal($('.emberTagInput-tag').length, 1);

        typeCharacterInInput('.js-ember-tag-input-new', String.fromCharCode(KEY_CODES.BACKSPACE));

        next(() => {
          assert.equal($('.emberTagInput-tag').length, 1);
          assert.equal($('.emberTagInput-tag--remove').length, 1);

          typeCharacterInInput('.js-ember-tag-input-new', String.fromCharCode(KEY_CODES.BACKSPACE));

          next(() => {
            assert.equal($('.emberTagInput-tag').length, 0);
            done();
          });
        });
      });
    });
  });

  test('Tags can contain spaces when allowSpacesInTags is set to true', async function(assert) {
    assert.expect(3);

    const tags = A();

    this.addTag = function(tag) {
      tags.pushObject(tag);
    };
    this.set('tags', tags);

    await render(hbs`
      {{#tag-input
        tags=tags
        addTag=(action addTag)
        allowSpacesInTags=true
        as |tag|
      }}
        {{tag}}
      {{/tag-input}}
    `);

    const done = assert.async();

    run(() => {
      typeInInput('.js-ember-tag-input-new', 'multiple words rock');

      $('.js-ember-tag-input-new').blur();

      next(() => {
        assert.equal($('.js-ember-tag-input-new').text(), '');
        assert.equal($('.emberTagInput-tag').length, 1);
        assert.equal($('.emberTagInput-tag').eq(0).text().trim(), 'multiple words rock');
        done();
      });
    });
  });

  test('Tags can\'t be added or removed in read only mode', async function(assert) {
    assert.expect(5);

    const tags = A(['hamburger', 'cheeseburger']);
    this.set('tags', tags);

    await render(hbs`
      {{#tag-input
        tags=tags
        readOnly=true
        as |tag|
      }}
        {{tag}}
      {{/tag-input}}
    `);

    assert.equal($('.emberTagInput-tag').length, 2);
    assert.equal($('.emberTagInput-remove').length, 0);
    assert.equal($('.emberTagInput-new').length, 1);

    const $input = $('.emberTagInput-new input');
    assert.equal($input.length, 1);
    assert.ok($input.prop('disabled'));
  });

  test('send input value when typing', async function(assert) {
    const tags = A();

    this.addTag = function(tag) {
      tags.pushObject(tag);
    };

    this.set('tags', tags);

    let inputValue;

    this.onKeyUp = function(value) {
      inputValue = value;
    };

    await render(hbs`
      {{#tag-input
        tags=tags
        addTag=(action addTag)
        onKeyUp=(action onKeyUp)
        as |tag|
      }}
        {{tag}}
      {{/tag-input}}
    `);

    const done = assert.async();

    run(() => {
      typeCharacterInInput('.js-ember-tag-input-new', 't', 'keyup');
      assert.equal(inputValue, 't');
      typeCharacterInInput('.js-ember-tag-input-new', 'e', 'keyup');
      assert.equal(inputValue, 'te');
      typeCharacterInInput('.js-ember-tag-input-new', 's', 'keyup');
      assert.equal(inputValue, 'tes');
      $('.js-ember-tag-input-new').blur();

      next(() => {
        assert.equal($('.emberTagInput-tag').length, 1);
        assert.equal($('.emberTagInput-tag').eq(0).text().trim(), 'tes');
        assert.equal(inputValue, '');
        done();
      });
    });
  });

  test('Tags can be added after readOnly changes to false', async function(assert) {
    assert.expect(4);

    const tags = A();

    this.addTag = function(tag) {
      tags.pushObject(tag);
    };
    this.set('tags', tags);
    this.set('readOnly', true);

    await render(hbs`
      {{#tag-input
        tags=tags
        addTag=(action addTag)
        readOnly=readOnly
        as |tag|
      }}
        {{tag}}
      {{/tag-input}}
    `);

    const done = assert.async();

    run(() => {
      this.set('readOnly', false);

      typeInInput('.js-ember-tag-input-new', 'some tag ');

      next(() => {
        assert.equal($('.js-ember-tag-input-new').text(), '');
        assert.equal($('.emberTagInput-tag').length, 2);
        assert.equal($('.emberTagInput-tag').eq(0).text().trim(), 'some');
        assert.equal($('.emberTagInput-tag').eq(1).text().trim(), 'tag');
        done();
      });
    });
  });

  test('Tags can\'t be added or removed after readOnly changes from false to true', async function(assert) {
    assert.expect(5);

    const tags = A(['hamburger', 'cheeseburger']);
    this.set('tags', tags);
    this.set('readOnly', false);

    await render(hbs`
      {{#tag-input
        tags=tags
        readOnly=true
        as |tag|
      }}
        {{tag}}
      {{/tag-input}}
    `);

    const done = assert.async();

    run(() => {
      this.set('readOnly', true);

      next(() => {
        assert.equal($('.emberTagInput-tag').length, 2);
        assert.equal($('.emberTagInput-remove').length, 0);
        assert.equal($('.emberTagInput-new').length, 1);

        const $input = $('.emberTagInput-new input');
        assert.equal($input.length, 1);
        assert.ok($input.prop('disabled'));
        done();
      });
    });
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions