Skip to content

docs(tests): Add specific guidance to testing standalone - #4611

Open
Zac-Smucker-Bryan wants to merge 3 commits into
ionic-team:mainfrom
Zac-Smucker-Bryan:zsb-ionic-docs
Open

docs(tests): Add specific guidance to testing standalone#4611
Zac-Smucker-Bryan wants to merge 3 commits into
ionic-team:mainfrom
Zac-Smucker-Bryan:zsb-ionic-docs

Conversation

@Zac-Smucker-Bryan

@Zac-Smucker-Bryan Zac-Smucker-Bryan commented Jul 31, 2026

Copy link
Copy Markdown

Resolves #3808

Description

  • Adds guidance about import componentOnReady for standalone projects from @ionic/core as a helper to improve testing when working with Ionic standalone, for Angular, React, and Vue
  • Adds a testing page for Vue (mostly a starter template with the standalone guidance above)
  • Adds specific testing example in the case of Angular w/the import implemented and then the helper called in the test.

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation
  • Other (CI, chores, etc.)

Rationale / Problems Fixed

Standalone users can't always consistently test what they need without better guidance.

Notes / Comments

There is a companion issue (ionic-team/ionic-framework#31312) and PR (ionic-team/ionic-framework#31313) in ionic-framework that might need to be coordinated for language tweaks.

For Angular, React, and Vue. Includes new testing page for Vue as a starter.
@Zac-Smucker-Bryan
Zac-Smucker-Bryan requested a review from a team as a code owner July 31, 2026 15:01
@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

@Zac-Smucker-Bryan is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ionic-docs Ready Ready Preview Aug 5, 2026 5:32pm

Request Review

Comment thread docs/angular/testing.md Outdated
Comment thread docs/angular/testing.md Outdated
Comment thread docs/angular/testing.md Outdated
Comment thread docs/angular/testing.md Outdated
Comment thread docs/react/testing/unit-testing/best-practices.md Outdated
Comment thread docs/vue/testing.md Outdated
/>
</head>

# Testing Ionic Vue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be consistent with the other pages and not use the frontmatter title.

Suggested change
# Testing Ionic Vue

Comment thread docs/vue/testing.md Outdated
Comment thread docs/vue/testing.md Outdated
Comment thread docs/vue/testing.md Outdated
Comment thread docs/vue/testing.md Outdated
Zac-Smucker-Bryan and others added 2 commits August 4, 2026 19:33
Clarity on use of componentOnReady, conciseness of test example

Co-authored-by: Maria Hutt <thetaPC@users.noreply.github.com>
Slight rephrasing of paragraph explaining componentOnReady helper
Add more concise test to Angular using componentOnReady helper
Move Angular to last part of Unit Testing
Add example test for React, matching Angular
Small formatting edits to Vue, add Vue testing page to sidebar
@Zac-Smucker-Bryan

Copy link
Copy Markdown
Author

Thanks for the feedback @thetaPC. I think I addressed all your comments. Let me know what else might need to be changed.

Comment on lines +57 to +73
```tsx
import { test, expect } from 'vitest';
import { render } from '@testing-library/react';
import { componentOnReady } from '@ionic/core';

import App from './App';

test('renders the submit button', async () => {
const { container } = render(<App />);

const button = container.querySelector('ion-button');

await new Promise<void>((resolve) => componentOnReady(button!, () => resolve()));

expect(button?.textContent).toContain('Submit');
});
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapped in IonApp to match the first best practice on this page, moved the non-null assertion to the query so the last line reads cleanly, and dropped the vitest import since the other snippets here stay runner agnostic.

Suggested change
```tsx
import { test, expect } from 'vitest';
import { render } from '@testing-library/react';
import { componentOnReady } from '@ionic/core';
import App from './App';
test('renders the submit button', async () => {
const { container } = render(<App />);
const button = container.querySelector('ion-button');
await new Promise<void>((resolve) => componentOnReady(button!, () => resolve()));
expect(button?.textContent).toContain('Submit');
});
```
```tsx
import { IonApp } from '@ionic/react';
import { render } from '@testing-library/react';
import { componentOnReady } from '@ionic/core';
import Example from './Example';
test('renders the submit button', async () => {
const { container } = render(
<IonApp>
<Example />
</IonApp>
);
const button = container.querySelector('ion-button')!;
await new Promise<void>((resolve) => componentOnReady(button, () => resolve()));
expect(button.textContent).toContain('Submit');
});

Comment thread docs/vue/testing.md

### Waiting for Components

When you need to wait for an Ionic component to render before asserting against its DOM, use the `componentOnReady` helper exported from `@ionic/core`. Do not call `el.componentOnReady()` directly. `@ionic/vue` uses Stencil's custom elements build, where that method does not exist on the element. The helper waits one animation frame instead, giving the component's inner contents a chance to render.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to mention it in the last review. This should also have an example like the other two frameworks. Consistency is very important for our docs.

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

Successfully merging this pull request may close these issues.

content: Ionic Angular Testing (Standalone etc)

2 participants