Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get property from component when testing?

How can I check component's property value when component doesn't have template? In application the component is extended and template is provided that way.

//my-component.js
export default Ember.Component.extend({
    foo: 'bar'
});

//my-component-test.hbs
integration: true;
test('it renders', function(assert) {
  this.set('foo2', 'foo2');
  this.render(hbs`{{my-component foo=foo2}}`);
  assert.equal(/* ??? */, 'foo2');
});

I am not able to use this.render(hbs'{{#my-component foo=foo2}}{{foo}}{{/my-component}}'); because foo is not yielded. Accessing component directly is not possible either.

like image 843
Keo Avatar asked Nov 25 '25 04:11

Keo


1 Answers

And the solution is to use unit test instead.

import { moduleForComponent, test } from 'ember-qunit';

moduleForComponent('forms/base-form', 'Unit | Component | forms/base-form field', {
  unit: true
});

test('it renders', function(assert) {
  const foo2 = 'foo2';
  const component = this.subject({foo: foo2});
  assert.equal(component.get('foo'), 'foo2');
});
like image 82
Keo Avatar answered Nov 28 '25 17:11

Keo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!