Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test
Browse files Browse the repository at this point in the history
EskiMojo14 committed Feb 6, 2024
1 parent 4230968 commit f92e8c9
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/toolkit/src/query/tests/buildCreateApi.test.tsx
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ describe('buildCreateApi', () => {
name: 'Timmy',
})

expect(memoize).toHaveBeenCalledTimes(4)
expect(memoize).toHaveBeenCalledTimes(2)

memoize.mockClear()

@@ -163,6 +163,6 @@ describe('buildCreateApi', () => {
)

// select() + selectFromResult
expect(memoize).toHaveBeenCalledTimes(8)
expect(memoize).toHaveBeenCalledTimes(4)
})
})
40 changes: 40 additions & 0 deletions packages/toolkit/src/query/tests/buildSelector.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
import { setupApiStore } from '../../tests/utils/helpers'

describe('buildSelector', () => {
interface Todo {
userId: number
id: number
title: string
completed: boolean
}

type Todos = Array<Todo>

const exampleApi = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({
baseUrl: 'https://jsonplaceholder.typicode.com',
}),
endpoints: (build) => ({
getTodos: build.query<Todos, string>({
query: () => '/todos',
}),
}),
})

const store = setupApiStore(exampleApi)
it('should memoize selector creation', () => {
expect(exampleApi.endpoints.getTodos.select('1')).toBe(
exampleApi.endpoints.getTodos.select('1'),
)

expect(exampleApi.endpoints.getTodos.select('1')).not.toBe(
exampleApi.endpoints.getTodos.select('2'),
)

expect(
exampleApi.endpoints.getTodos.select('1')(store.store.getState()),
).toBe(exampleApi.endpoints.getTodos.select('1')(store.store.getState()))
})
})

0 comments on commit f92e8c9

Please sign in to comment.