Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/angular/testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ When doing component class testing, the component object is accessed using the c

### Waiting for Components {/* #waiting-for-components */}

When testing Ionic components, use the `componentOnReady` helper exported from `@ionic/core` rather than calling `el.componentOnReady()` directly. The `el.componentOnReady()` method only exists on lazy-loaded elements and calling it directly throws an error on custom-element builds, which is what standalone projects use. The helper handles both. It awaits the element's own `componentOnReady()` promise when that exists. Otherwise it waits one animation frame, giving the component's inner contents a chance to render. Wait for the callback before asserting against the rendered DOM or running accessibility tests.
When testing Ionic components, use the `componentOnReady` helper exported from `@ionic/angular` (or `@ionic/angular/lazy` in lazy loaded apps) rather than calling `el.componentOnReady()` directly. The `el.componentOnReady()` method only exists on lazy-loaded elements and calling it directly throws an error on custom-element builds, which is what standalone projects use. The helper handles both. It awaits the element's own `componentOnReady()` promise when that exists. Otherwise it waits one animation frame, giving the component's inner contents a chance to render. Wait for the callback before asserting against the rendered DOM or running accessibility tests.

```tsx
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { componentOnReady } from '@ionic/core';
import { componentOnReady } from '@ionic/angular';
import { HomePage } from './home.page';

describe('HomePage', () => {
Expand Down
5 changes: 2 additions & 3 deletions docs/react/testing/unit-testing/best-practices.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ For more information on `user-event`, refer to the [user-event documentation](ht

## Waiting for Components {/* #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/react` 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.
When you need to wait for an Ionic component to render before asserting against its DOM, use the `componentOnReady` helper exported from `@ionic/react`. Do not call `el.componentOnReady()` directly. `@ionic/react` 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.

```tsx
import { IonApp } from '@ionic/react';
import { IonApp, componentOnReady } from '@ionic/react';
import { render } from '@testing-library/react';
import { componentOnReady } from '@ionic/core';

import Example from './Example';

Expand Down
56 changes: 51 additions & 5 deletions docs/techniques/security.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,63 @@ Developers can assign a CSP to their application by setting a meta tag with the

Ionic Framework provides a function to help developers set the nonce value used when constructing the web component stylesheets. This function should be called before any Ionic components are loaded. This is required to pass the nonce value to the web components so that they can be used in a CSP environment.

```ts
import { setNonce } from '@ionic/core/loader';
````mdx-code-block
<Tabs
groupId="framework"
defaultValue="angular"
values={[
{ value: 'angular', label: 'Angular' },
{ value: 'angular-standalone', label: 'Angular (Standalone)' },
{ value: 'javascript', label: 'JavaScript' },
{ value: 'react', label: 'React' },
{ value: 'vue', label: 'Vue' },
]
}>
<TabItem value="angular">

```ts title="src/main.ts"
import { setNonce } from '@ionic/angular/lazy';

setNonce('randomNonceGoesHere');
```
</TabItem>
<TabItem value="angular-standalone">

:::tip
```ts title="src/main.ts"
import { setNonce } from '@ionic/angular';

setNonce('randomNonceGoesHere');
```
</TabItem>
<TabItem value="javascript">

In Angular this can be called in the `main.ts` file, before the application is bootstrapped.
```html title="index.html"
<head>
<meta name="csp-nonce" content="randomNonceGoesHere" />
</head>
```

:::
Ionic reads the nonce from this tag when it adds component styles, however Ionic is loaded. If your app imports from `@ionic/core/loader` or `@ionic/core/components`, you can call `setNonce` from that package instead.

</TabItem>
<TabItem value="react">

```ts title="src/main.tsx"
import { setNonce } from '@ionic/react';

setNonce('randomNonceGoesHere');
```
</TabItem>
<TabItem value="vue">

```ts title="src/main.ts"
import { setNonce } from '@ionic/vue';

setNonce('randomNonceGoesHere');
```
</TabItem>
</Tabs>
````

For more information on how to use CSPs with Stencil web components, refer to the [Stencil documentation](https://stenciljs.com/docs/csp-nonce).

Expand Down
4 changes: 2 additions & 2 deletions docs/vue/testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ This document provides an overview of how to test an application built with `@io

### Waiting for Components {/* #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.
When you need to wait for an Ionic component to render before asserting against its DOM, use the `componentOnReady` helper exported from `@ionic/vue`. 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.

```ts
import { mount } from '@vue/test-utils';
import { componentOnReady } from '@ionic/core';
import { componentOnReady } from '@ionic/vue';

import Example from './Example.vue';

Expand Down
48 changes: 33 additions & 15 deletions static/code/stackblitz/v9/angular/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions static/code/stackblitz/v9/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"@angular/platform-browser": "^22.0.0",
"@angular/platform-browser-dynamic": "^22.0.0",
"@angular/router": "^22.0.0",
"@ionic/angular": "9.0.13-dev.11795209321.12c3c69e",
"@ionic/core": "9.0.13-dev.11795209321.12c3c69e",
"@ionic/angular": "9.0.15-dev.11796247574.1ecbe59d",
"@ionic/core": "9.0.15-dev.11796247574.1ecbe59d",
"ionicons": "8.1.0",
"rxjs": "^7.8.1",
"tslib": "^2.5.0"
Expand Down
27 changes: 18 additions & 9 deletions static/code/stackblitz/v9/html/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion static/code/stackblitz/v9/html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "vite preview"
},
"dependencies": {
"@ionic/core": "9.0.13-dev.11795209321.12c3c69e",
"@ionic/core": "9.0.15-dev.11796247574.1ecbe59d",
"ionicons": "8.1.0"
},
"devDependencies": {
Expand Down
46 changes: 23 additions & 23 deletions static/code/stackblitz/v9/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions static/code/stackblitz/v9/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@ionic/react": "9.0.13-dev.11795209321.12c3c69e",
"@ionic/react-router": "9.0.13-dev.11795209321.12c3c69e",
"@ionic/react": "9.0.15-dev.11796247574.1ecbe59d",
"@ionic/react-router": "9.0.15-dev.11796247574.1ecbe59d",
"@types/node": "^24.0.0",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
Expand Down
Loading
Loading