Skip to content

Commit

Permalink
chore: Service cannot be used before helper failing test
Browse files Browse the repository at this point in the history
- When `fileQueue` service is used _before_ `(fileQueue)` helper, then app fails with:

```
ember.js:626 Uncaught (in promise) Error: Assertion Failed: You attempted to update `_value` on `TrackedStorageImpl`, but it had already been used previously in the same computation.  Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.

`_value` was first used:

- While rendering:
  -top-level
    application
      index
        (unknown template-only component)
          (result of a `unknown` helper)
            (result of a `unknown` helper)
              (result of a `unknown` helper)
                false.files
```
- This PR is just to document the issue described in adopted-ember-addons#1085
  • Loading branch information
MichalBryxi committed Sep 25, 2024
1 parent 5bc0e4a commit 2929c24
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion test-app/tests/integration/helpers/file-queue-helper-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { render, click, settled, waitFor } from '@ember/test-helpers';
import { DEFAULT_QUEUE, FileState } from 'ember-file-upload';
import type { UploadFile } from 'ember-file-upload';
import { selectFiles } from 'ember-file-upload/test-support';
import { uploadHandler } from 'ember-file-upload';
import { type FileQueueService, uploadHandler } from 'ember-file-upload';
import { later } from '@ember/runloop';
import fileQueue from 'ember-file-upload/helpers/file-queue';
import { on } from '@ember/modifier';
Expand All @@ -20,6 +20,31 @@ module('Integration | Helper | file-queue', function (hooks) {
setupRenderingTest(hooks);
setupMirage(hooks);

test('service can be used before helper', async function (assert) {
const fileQueueService = this.owner.lookup(
'service:file-queue',
) as FileQueueService;

await render(
<template>
<ul>
{{#each fileQueueService.files as |file|}}
<li>
{{file.name}}
</li>
{{/each}}
</ul>

{{#let (fileQueue) as |queue|}}
<label>
<input type='file' {{queue.selectFile}} hidden />
Select File
</label>
{{/let}}
</template>,
);
});

test('filter is triggered when selecting files', async function (assert) {
const filter = (file: File) => {
assert.step(`filter: ${file.name}`);
Expand Down

0 comments on commit 2929c24

Please sign in to comment.