Skip to content

Commit f183771

Browse files
committed
fix tests 2
1 parent e00d732 commit f183771

File tree

6 files changed

+68
-1
lines changed

6 files changed

+68
-1
lines changed

.github/instructions/react.instructions.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ applyTo: "**/*.tsx"
3535
- Always provide stable keys in lists. Avoid using array indices as keys.
3636
- Avoid `setState`/`useState` updates based on stale closures. Prefer functional
3737
updates when derived from previous state.
38+
39+
```ts
40+
// Prefer:
41+
setCount((oldCount: number): number => oldCount + 1)
42+
43+
// Over:
44+
setCount(oldCount + 1)
45+
```

packages/eslint-config/.vscode/launch.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"configurations": [
33
{
4+
"console": "integratedTerminal",
45
"name": "Build",
56
"request": "launch",
67
"runtimeArgs": ["run", "build"],
78
"runtimeExecutable": "npm",
9+
"skipFiles": ["<node_internals>/**"],
810
"type": "node",
911
}
1012
],
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { mapObjectToEntries } from './index.js';
3+
4+
describe('mapObjectToEntries', (): void => {
5+
it('should map an object to entries', (): void => {
6+
expect(mapObjectToEntries({ bool: true, num: 123, str: 'test' })).toEqual([
7+
['bool', true],
8+
['num', 123],
9+
['str', 'test'],
10+
]);
11+
});
12+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { mapObjectToKeys } from './index.js';
3+
4+
describe('mapObjectToKeys', (): void => {
5+
it('should map an object to its keys', (): void => {
6+
expect(mapObjectToKeys({ bool: true, num: 123, str: 'test' })).toEqual([
7+
'bool',
8+
'num',
9+
'str',
10+
]);
11+
});
12+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { ApiV2 } from '@fullstory/snippet';
2+
import { renderHook } from '@testing-library/react';
3+
import { describe, expect, it, vi } from 'vitest';
4+
import useMockFullstoryBrowser from './use-mock-fullstory-browser.js';
5+
6+
const TEST_FULL_STORY = vi.fn();
7+
8+
describe('useMockFullstoryBrowser', (): void => {
9+
describe('FullStory', (): void => {
10+
it('should default to no-op', (): void => {
11+
const { result } = renderHook(useMockFullstoryBrowser);
12+
13+
const { FullStory: fullStory } = result.current;
14+
15+
expect((): void => {
16+
fullStory('init');
17+
}).not.toThrow();
18+
});
19+
20+
it('should call a provided Fullstory API', (): void => {
21+
const { result } = renderHook(useMockFullstoryBrowser, {
22+
initialProps: {
23+
FullStory: TEST_FULL_STORY as unknown as ApiV2,
24+
},
25+
});
26+
27+
const { FullStory: fullStory } = result.current;
28+
fullStory('init');
29+
30+
expect(TEST_FULL_STORY).toHaveBeenCalledWith('init');
31+
});
32+
});
33+
});

packages/fullstory-react/src/hooks/use-mock-fullstory-browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import useShallowMemo from 'use-shallow-memo';
66
import merge from '../utils/merge.js';
77

88
export default function useMockFullstoryBrowser(
9-
partial: Partial<Omit<typeof fullstoryBrowser, 'default'>>,
9+
partial: Partial<Omit<typeof fullstoryBrowser, 'default'>> = {},
1010
): Omit<typeof fullstoryBrowser, 'default'> {
1111
// States
1212
const [initialized, setInitialized] = useState(false);

0 commit comments

Comments
 (0)