Skip to content

Commit

Permalink
fix test types
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaskasky committed Dec 12, 2024
1 parent b326dde commit d8037ec
Showing 1 changed file with 38 additions and 47 deletions.
85 changes: 38 additions & 47 deletions tests/vanilla/unstable_derive.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,23 @@ describe('unstable_derive for scoping atoms', () => {
const scopedAtoms = new Set<Atom<unknown>>([a])

const store = createStore()
const derivedStore = store.unstable_derive(
(getAtomState, atomRead, atomWrite, atomOnMount) => {
const scopedAtomStateMap = new WeakMap()
return [
(atom) => {
if (scopedAtoms.has(atom)) {
let atomState = scopedAtomStateMap.get(atom)
if (!atomState) {
atomState = { d: new Map(), p: new Set(), n: 0 }
scopedAtomStateMap.set(atom, atomState)
}
return atomState
const derivedStore = store.unstable_derive((getAtomState, ...args) => {
const scopedAtomStateMap = new WeakMap()

Check failure on line 17 in tests/vanilla/unstable_derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.8.3)

Argument of type '(getAtomState: <Value>(pending: Pending | undefined, atom: Atom<Value>) => AtomState<Value>, args_1: <Value>(pending: Pending | undefined, atom: Atom<...>, get: Getter, options: { ...; }) => Value, args_2: <Value, Args extends unknown[], Result>(pending: Pending, atom: WritableAtom<...>, ...params: Parameters<...>) ...' is not assignable to parameter of type '(args_0: <Value>(pending: Pending | undefined, atom: Atom<Value>) => AtomState<Value>, args_1: <Value>(pending: Pending | undefined, atom: Atom<Value>, get: Getter, options: { ...; }) => Value, args_2: <Value, Args extends unknown[], Result>(pending: Pending, atom: WritableAtom<...>, ...params: Parameters<...>) => R...'.
return [
(pending, atom) => {
if (scopedAtoms.has(atom)) {
let atomState = scopedAtomStateMap.get(atom)
if (!atomState) {
atomState = { d: new Map(), p: new Set(), n: 0 }
scopedAtomStateMap.set(atom, atomState)
}
return getAtomState(atom)
},
atomRead,
atomWrite,
atomOnMount,
]
},
)
return atomState
}
return getAtomState(pending, atom)
},
...args,
]
})

expect(store.get(a)).toBe('a')
expect(derivedStore.get(a)).toBe('a')
Expand All @@ -58,27 +54,23 @@ describe('unstable_derive for scoping atoms', () => {
const scopedAtoms = new Set<Atom<unknown>>([a])

const store = createStore()
const derivedStore = store.unstable_derive(
(getAtomState, atomRead, atomWrite, atomOnMount) => {
const scopedAtomStateMap = new WeakMap()
return [
(atom) => {
if (scopedAtoms.has(atom)) {
let atomState = scopedAtomStateMap.get(atom)
if (!atomState) {
atomState = { d: new Map(), p: new Set(), n: 0 }
scopedAtomStateMap.set(atom, atomState)
}
return atomState
const derivedStore = store.unstable_derive((getAtomState, ...args) => {
const scopedAtomStateMap = new WeakMap()

Check failure on line 58 in tests/vanilla/unstable_derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.8.3)

Argument of type '(getAtomState: <Value>(pending: Pending | undefined, atom: Atom<Value>) => AtomState<Value>, args_1: <Value>(pending: Pending | undefined, atom: Atom<...>, get: Getter, options: { ...; }) => Value, args_2: <Value, Args extends unknown[], Result>(pending: Pending, atom: WritableAtom<...>, ...params: Parameters<...>) ...' is not assignable to parameter of type '(args_0: <Value>(pending: Pending | undefined, atom: Atom<Value>) => AtomState<Value>, args_1: <Value>(pending: Pending | undefined, atom: Atom<Value>, get: Getter, options: { ...; }) => Value, args_2: <Value, Args extends unknown[], Result>(pending: Pending, atom: WritableAtom<...>, ...params: Parameters<...>) => R...'.
return [
(pending, atom) => {
if (scopedAtoms.has(atom)) {
let atomState = scopedAtomStateMap.get(atom)
if (!atomState) {
atomState = { d: new Map(), p: new Set(), n: 0 }
scopedAtomStateMap.set(atom, atomState)
}
return getAtomState(atom)
},
atomRead,
atomWrite,
atomOnMount,
]
},
)
return atomState
}
return getAtomState(pending, atom)
},
...args,
]
})

expect(store.get(c)).toBe('ab')
expect(derivedStore.get(c)).toBe('ab')
Expand All @@ -103,10 +95,10 @@ describe('unstable_derive for scoping atoms', () => {
function makeStores() {
const store = createStore()
const derivedStore = store.unstable_derive(
(getAtomState, atomRead, atomWrite, atomOnMount) => {
(getAtomState, atomRead, ...args) => {
const scopedAtomStateMap = new WeakMap()

Check failure on line 99 in tests/vanilla/unstable_derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.8.3)

Argument of type '(getAtomState: <Value>(pending: Pending | undefined, atom: Atom<Value>) => AtomState<Value>, atomRead: <Value>(pending: Pending | undefined, atom: Atom<...>, get: Getter, options: { ...; }) => Value, args_2: <Value, Args extends unknown[], Result>(pending: Pending, atom: WritableAtom<...>, ...params: Parameters<...>...' is not assignable to parameter of type '(args_0: <Value>(pending: Pending | undefined, atom: Atom<Value>) => AtomState<Value>, args_1: <Value>(pending: Pending | undefined, atom: Atom<Value>, get: Getter, options: { ...; }) => Value, args_2: <Value, Args extends unknown[], Result>(pending: Pending, atom: WritableAtom<...>, ...params: Parameters<...>) => R...'.
return [
(atom) => {
(pending, atom) => {
if (scopedAtoms.has(atom)) {
let atomState = scopedAtomStateMap.get(atom)
if (!atomState) {
Expand All @@ -115,19 +107,18 @@ describe('unstable_derive for scoping atoms', () => {
}
return atomState
}
return getAtomState(atom)
return getAtomState(pending, atom)
},
(a, get, options) => {
(pending, a, get, options) => {
const myGet: Getter = (aa) => {
if (scopedAtoms.has(aa)) {
scopedAtoms.add(a) // Is this too naive?
}
return get(aa)
}
return atomRead(a, myGet, options)
return atomRead(pending, a, myGet, options)
},
atomWrite,
atomOnMount,
...args,
]
},
)
Expand Down

0 comments on commit d8037ec

Please sign in to comment.