How do you test a glimmer.js argument?

175 Views Asked by At

How do you properly pass an argument to a glimmer.js component in testing?

For example, I have a component that accepts @story as an argument, to which I pass a story object. It actually works fine in the code, but I am trying to learn how to test Glimmer components and I can't find a single bit of documentation on passing in arguments in a test environment.

I tried the following, and it obviously doesn't work, but am I close?

test('it displays args', async function(assert) {
  const storySample = {as_a: 'person', i_want: 'happiness', so_that: 'I can be happy'};

  await this.render(hbs`<StoryViewer @story={{theStory}} />`, {theStory: storySample});

  assert.equal(this.containerElement.textContent.trim(),
    'As a person I want happiness so that I can be happy');
});

Update

New things that don't work:

await this.render(hbs`<StoryViewer @story={{theStory}} />`);
this.args = {'theStory': storySample};

await this.render(hbs`<StoryViewer />`);
this.args = {'story': storySample};

await this.render(hbs`<StoryViewer />`);
this.args = {'@story': storySample};

Update 1/5/2018

I eventually was directed to an issue about this topic in the glimmer.js repo. For anyone running into this problem, you can check out this issue:

https://github.com/glimmerjs/glimmer.js/issues/14

Spoiler: It is a comparatively old issue, and all the links inside it (as of this writing) are rabbit holes where some issues got closed because they are "rethinking" what the way that they are doing things. So, basically, it is still not possible to do this cleanly.

I am guessing that there is some kind of ugly way to do this, but I am not interested in that, so I have temporarily abandoned Glimmer.js until tests are better.

0

There are 0 best solutions below