Skip to content

Commit

Permalink
docs: add section on testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ignace committed Nov 11, 2023
1 parent 938509e commit eb75f7e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,29 @@ export default class Hello extends Component {
}
```

Template tag components can also be used for writing tests. In fact, this aligned syntax between app code and test code is one of the big advantages of the new authoring format.

Just like in app code, the template tag has access to the outer scope. This means you can reference variables directly in your tests:

```js
// tests/integration/components/hello-test.gjs
import Hello from 'example-app/components/hello';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';

module('Integration | Component | hello', function (hooks) {
setupRenderingTest(hooks);

test('renders name argument', async function (assert) {
const name = 'world';
await render(<template><Hello @name={{name}} /></template>);
assert.dom('[data-test-id="some-selector"]').hasText(name);
});
});

```

## Reference: built-in helpers, modifiers, components

As implemented as part of the [Strict Mode Templates RFC][rfc-496], the built in
Expand Down

0 comments on commit eb75f7e

Please sign in to comment.