Skip to content

Commit

Permalink
test: add storage subscribe cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkx committed Jan 23, 2024
1 parent 7f4ae99 commit 37d7250
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 14 deletions.
1 change: 0 additions & 1 deletion examples/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"lint:type": "tsc --noEmit"
},
"dependencies": {
"@rsbuild/plugin-babel": "^0.3.5",
"@webx-kit/runtime": "workspace:^",
"solid-js": "^1.8.11"
},
Expand Down
11 changes: 11 additions & 0 deletions packages/storage/e2e/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChromeStorage } from '@/index';

declare module globalThis {
const __storage: ChromeStorage;
let __log: unknown[];
}

test('Set Item', async ({ background }) => {
Expand All @@ -29,3 +30,13 @@ test('Clear', async ({ background }) => {
await expect(background.evaluate(() => globalThis.__storage.getItem('A'))).resolves.toBeNull();
await expect(background.evaluate(() => globalThis.__storage.getItem('B'))).resolves.toBeNull();
});

test('Subscribe', async ({ background }) => {
await background.evaluate(() => (globalThis.__log = []));
await background.evaluate(() => globalThis.__storage.subscribe('A', globalThis.__log.push.bind(globalThis.__log)));

await background.evaluate(() => globalThis.__storage.setItem('A', 'Hello'));
await background.evaluate(() => globalThis.__storage.removeItem('A'));

await expect(background.evaluate(() => globalThis.__log)).resolves.toEqual(['Hello', null]);
});
105 changes: 92 additions & 13 deletions pnpm-lock.yaml

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

0 comments on commit 37d7250

Please sign in to comment.