Skip to content

Commit

Permalink
test: add test for array and object signal update
Browse files Browse the repository at this point in the history
  • Loading branch information
aidlran committed Mar 19, 2024
1 parent 67f5743 commit 09aa091
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
{
"files": ["*.test.js"],
"rules": {
"@typescript-eslint/no-floating-promises": "off"
"@typescript-eslint/no-floating-promises": 0,
"@typescript-eslint/no-unsafe-argument": 0,
"@typescript-eslint/no-unsafe-return": 0
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ concurrency:
cancel-in-progress: true

jobs:
lint:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
36 changes: 36 additions & 0 deletions src/signal/signals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,42 @@ describe('signal', () => {
check(1, 1);
});
});

test('notifies on array update', async () => {
const [get, set] = signal([]);
let expect = 0;
const unsubscribe = effect(() => {
strictEqual(expect, get().length);
});
expect++;
set(
(() => {
const a = get();
a.push({});
return a;
})(),
);
await tick();
unsubscribe();
});

test('notifies on object update', async () => {
const [get, set] = signal({});
let expect = 0;
const unsubscribe = effect(() => {
strictEqual(expect, Object.keys(get()).length);
});
expect++;
set(
(() => {
const a = get();
a.a = '';
return a;
})(),
);
await tick();
unsubscribe();
});
});

test('effect', async () => {
Expand Down

0 comments on commit 09aa091

Please sign in to comment.