Skip to content
Merged
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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
"@rollup/plugin-commonjs": "^28.0.6",
"@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-typescript": "^12.1.4",
"@symfony/stimulus-testing": "^2.0.1",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/user-event": "^14.6.1",
"@types/node": "^22.6.0",
"@vitest/browser": "^2.1.1",
"jsdom": "^26.1.0",
"lightningcss": "^1.28.2",
"playwright": "^1.47.0",
"rollup": "^4.44.1",
Expand Down
4 changes: 2 additions & 2 deletions src/Cropperjs/assets/test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import CropperjsController from '../src/controller';

let cropper: Cropper | null = null;
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('CropperjsController', () => {
beforeEach(() => {
container = mountDOM(`
<div id="form_photo" class="cropperjs">
<input type="hidden" id="form_photo_options" name="form[photo][options]"
<input type="hidden" id="form_photo_options" name="form[photo][options]"
data-testid="input"
data-controller="check cropperjs"
data-cropperjs-public-url-value="https://symfony.com/logos/symfony_black_02.png"
Expand Down
22 changes: 11 additions & 11 deletions src/Dropzone/assets/test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import user from '@testing-library/user-event';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import DropzoneController from '../src/controller';

// Controller used to check the actual controller was properly booted
Expand All @@ -33,35 +33,35 @@ describe('DropzoneController', () => {

beforeEach(() => {
container = mountDOM(`
<div class="dropzone-container" data-controller="check dropzone" data-testid="container">
<div class="dropzone-container" data-controller="check dropzone" data-testid="container">
<input type="file"
style="display: none"
data-dropzone-target="input"
data-testid="input" />
<div class="dropzone-placeholder"
data-dropzone-target="placeholder"

<div class="dropzone-placeholder"
data-dropzone-target="placeholder"
data-testid="placeholder">
Placeholder
</div>

<div class="dropzone-preview"
data-dropzone-target="preview"
data-testid="preview"
style="display: none">

<button type="button"
class="dropzone-preview-button"
data-dropzone-target="previewClearButton"
data-testid="button"></button>

<div class="dropzone-preview-image"
data-dropzone-target="previewImage"
data-testid="preview-image"
style="display: none"></div>

<div class="dropzone-preview-filename"
data-dropzone-target="previewFilename"
data-dropzone-target="previewFilename"
data-testid="preview-filename"></div>
</div>
</div>
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('DropzoneController', () => {
const input = getByTestId(container, 'input');
const file = new File(['hello'], 'hello.png', { type: 'image/png' });

user.upload(input, file);
await user.upload(input, file);
expect(input.files[0]).toStrictEqual(file);

// The dropzone should be in preview mode
Expand Down
4 changes: 2 additions & 2 deletions src/LazyImage/assets/test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import LazyImageController from '../src/controller';

// Controller used to check the actual controller was properly booted
Expand All @@ -35,7 +35,7 @@ describe('LazyImageController', () => {

beforeEach(() => {
container = mountDOM(`
<img
<img
src="https://symfony.com/logos/symfony_black_02.png"
srcset="https://symfony.com/logos/symfony_black_02.png 1x, https://symfony.com/logos/symfony_black_02.png 2x"
data-testid="img"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('ExternalMutationTracker', () => {
expect(changes.getChangedStyles()).toEqual([
{ name: 'display', value: 'inline' },
{ name: 'color', value: 'red' },
{ name: 'background-image', value: 'url(https://example.com/image.png)' },
{ name: 'background-image', value: 'url("https://example.com/image.png")' },
]);
expect(changes.getRemovedStyles()).toEqual(['margin']);
});
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('ExternalMutationTracker', () => {

it('can track class changes with whitespaces', async () => {
const { element, tracker } = createTracker(`
<div
<div
class="
first-class
second-class
Expand Down
3 changes: 1 addition & 2 deletions src/Map/assets/test/abstract_map_controller.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Application } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import * as L from 'leaflet';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import AbstractMapController from '../src/abstract_map_controller.ts';

class MyMapController extends AbstractMapController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import { clearDOM, mountDOM } from '../../../../../../../test/stimulus-helpers';
import GoogleController from '../src/map_controller';

// Controller used to check the actual controller was properly booted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import { clearDOM, mountDOM } from '../../../../../../../test/stimulus-helpers';
import LeafletController from '../src/map_controller';

// Controller used to check the actual controller was properly booted
Expand Down
2 changes: 1 addition & 1 deletion src/Notify/assets/test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import { vi } from 'vitest';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import NotifyController from '../src/controller';

// Controller used to check the actual controller was properly booted
Expand Down
2 changes: 1 addition & 1 deletion src/React/assets/test/render_controller.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import React from 'react';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import ReactController from '../src/render_controller';

// Controller used to check the actual controller was properly booted
Expand Down
2 changes: 1 addition & 1 deletion src/Svelte/assets/test/render_controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import SvelteController from '../src/render_controller';
import MyComponent from './fixtures/MyComponent.svelte';

Expand Down
12 changes: 6 additions & 6 deletions src/Swup/assets/test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import SwupController from '../src/controller';

let actualSwupOptions: any = null;
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('SwupController', () => {
<title>Symfony UX</title>
</head>
<body>
<div
<div
data-testid="body"
data-controller="check swup"
data-swup-containers-value="[&quot;#swup&quot;, &quot;#nav&quot;]"
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('SwupController', () => {
<title>Symfony UX</title>
</head>
<body>
<div
<div
data-testid="body"
data-controller="check swup"
data-swup-link-selector-value="a"
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('SwupController', () => {
<title>Symfony UX</title>
</head>
<body>
<div
<div
data-testid="body"
data-controller="check swup"
data-swup-main-element-value="#main"
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('SwupController', () => {
<title>Symfony UX</title>
</head>
<body>
<div
<div
data-testid="body"
data-controller="check swup"
data-swup-containers-value="[&quot;#swup&quot;, &quot;#nav&quot;]"
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('SwupController', () => {
<title>Symfony UX</title>
</head>
<body>
<div
<div
data-testid="body"
data-controller="check swup"
data-swup-main-element-value="#main"
Expand Down
4 changes: 2 additions & 2 deletions src/TogglePassword/assets/test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, getByText, waitFor } from '@testing-library/dom';
import user from '@testing-library/user-event';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import TogglePasswordController from '../src/controller';

// Controller used to check the actual controller was properly booted
Expand All @@ -33,7 +33,7 @@ describe('TogglePasswordController', () => {

beforeEach(() => {
container = mountDOM(`
<div class="toggle-password-container">
<div class="toggle-password-container">
<input type="password"
data-testid="input"
data-controller="check toggle-password"
Expand Down
2 changes: 1 addition & 1 deletion src/Turbo/assets/test/turbo_controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { Application } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId } from '@testing-library/dom';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import TurboController from '../src/turbo_controller';

const startStimulus = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Turbo/assets/test/turbo_stream_controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import { Application } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId } from '@testing-library/dom';
import { vi } from 'vitest';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import TurboStreamController from '../src/turbo_stream_controller';

const startStimulus = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/Typed/assets/test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import TypedController from '../src/controller';

// Controller used to check the actual controller was properly booted
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('TypedController', () => {
<head>
<title>Symfony UX</title>
</head>
<body>
<body>
<div>
I created this UX component because <span
data-testid="typed"
Expand Down
2 changes: 1 addition & 1 deletion src/Vue/assets/test/render_controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { Application, Controller } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import { getByTestId, waitFor } from '@testing-library/dom';
import { clearDOM, mountDOM } from '../../../../test/stimulus-helpers';
import VueController from '../src/render_controller';

// Controller used to check the actual controller was properly booted
Expand Down
2 changes: 1 addition & 1 deletion test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* file that was distributed with this source code.
*/

import '@symfony/stimulus-testing/setup';
import '@testing-library/jest-dom';
20 changes: 20 additions & 0 deletions test/stimulus-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

export function mountDOM(html: string = '') {
const div = document.createElement('div');
div.innerHTML = html;
document.body.appendChild(div);

return div;
}

export function clearDOM() {
document.body.innerHTML = '';
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"composite": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true
"resolveJsonModule": true,
"types": ["vitest/globals", "@testing-library/jest-dom"]
},
"include": ["bin/**/*.ts"]
}
Loading