Skip to content

Commit 89ffcb0

Browse files
committed
update
1 parent 7838076 commit 89ffcb0

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

packages/solid-test/src/trigger/__tests__/index.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,22 @@ describe('trigger', () => {
1414
trigger.run()
1515
expect(callback).toHaveBeenCalled()
1616
})
17+
it('should get changed count', () => {
18+
const trigger = createTrigger()
19+
const callback = vi.fn()
20+
21+
expect(trigger.changed).toBe(0)
22+
trigger.target = callback
23+
expect(trigger.changed).toBe(1)
24+
trigger.target = callback
25+
expect(trigger.changed).toBe(2)
26+
})
27+
it('should get target', () => {
28+
const trigger = createTrigger()
29+
const callback = vi.fn()
30+
31+
expect(trigger.target).toBeUndefined()
32+
trigger.target = callback
33+
expect(trigger.target).toBe(callback)
34+
})
1735
})
Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import {jsonStringify} from '../'
2-
import {describe, expect, it} from 'vitest'
2+
import {describe, expect, it, vi} from 'vitest'
3+
import {stringify} from 'safe-stable-stringify'
4+
5+
vi.mock('safe-stable-stringify', async () => {
6+
const module: any = await import('safe-stable-stringify')
7+
8+
return {
9+
...module,
10+
stringify: vi.fn(module.stringify),
11+
}
12+
})
313
describe('jsonStringify', () => {
414
it('should return string', async () => {
515
const result = jsonStringify({
@@ -8,13 +18,23 @@ describe('jsonStringify', () => {
818

919
expect(result).toBe('{"foo":"foo"}')
1020
})
11-
// todo fix test
12-
it.skip('should return string', async () => {
21+
it('should return string with circular', async () => {
1322
const obj = {props: {} as any}
1423

1524
obj.props = obj
1625
const result = jsonStringify(obj)
1726

27+
expect(result).toBe('{"props":"[Circular]"}')
28+
})
29+
it('should return empty defaultValue when error occurs', async () => {
30+
// mock stringify to throw error
31+
vi.mocked(stringify).mockImplementation(() => {
32+
throw new Error('test')
33+
})
34+
const result = jsonStringify({
35+
foo: '',
36+
})
37+
1838
expect(result).toBe('')
1939
})
2040
})

0 commit comments

Comments
 (0)