-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b4b403
commit eabe879
Showing
9 changed files
with
228 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe('InfiniteQuery', () => { | ||
it('should work', () => {}); | ||
|
||
it('should work with signals', () => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe('IsFetching', () => { | ||
it('should work', () => {}); | ||
|
||
it('should work with signals', () => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe('IsMutating', () => { | ||
it('should work', () => {}); | ||
|
||
it('should work with signals', () => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
describe('mutation', () => { | ||
it('should work', () => {}); | ||
|
||
it('should work with signals', () => {}); | ||
|
||
it('should be typed', () => {}); | ||
|
||
it('should work with callback handlers', () => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
describe('Operators', () => { | ||
describe('mapResultData', () => { | ||
it('should map the data of a successful result', () => { | ||
// Write your test here | ||
}); | ||
|
||
// Additional tests for mapResultData | ||
}); | ||
|
||
describe('filterSuccessResult', () => { | ||
it('should filter only success results', () => { | ||
// Write your test here | ||
}); | ||
|
||
// Additional tests for filterSuccessResult | ||
}); | ||
|
||
describe('filterErrorResult', () => { | ||
it('should filter only error results', () => { | ||
// Write your test here | ||
}); | ||
|
||
// Additional tests for filterErrorResult | ||
}); | ||
|
||
describe('tapSuccessResult', () => { | ||
it('should tap into a success result', () => { | ||
// Write your test here | ||
}); | ||
|
||
// Additional tests for tapSuccessResult | ||
}); | ||
|
||
describe('tapErrorResult', () => { | ||
it('should tap into an error result', () => { | ||
// Write your test here | ||
}); | ||
|
||
// Additional tests for tapErrorResult | ||
}); | ||
|
||
describe('takeUntilResultFinalize', () => { | ||
it('should take values until result finalizes', () => { | ||
// Write your test here | ||
}); | ||
|
||
// Additional tests for takeUntilResultFinalize | ||
}); | ||
|
||
describe('takeUntilResultSuccess', () => { | ||
it('should take values until success result', () => { | ||
// Write your test here | ||
}); | ||
|
||
// Additional tests for takeUntilResultSuccess | ||
}); | ||
|
||
describe('takeUntilResultError', () => { | ||
it('should take values until error result', () => { | ||
// Write your test here | ||
}); | ||
|
||
// Additional tests for takeUntilResultError | ||
}); | ||
|
||
describe('startWithQueryResult', () => { | ||
it('should start with a default query result', () => { | ||
// Write your test here | ||
}); | ||
|
||
// Additional tests for startWithQueryResult | ||
}); | ||
|
||
describe('intersectResults$', () => { | ||
it('should intersect and map multiple query results', () => { | ||
// Write your test here | ||
}); | ||
|
||
// Additional tests for intersectResults$ | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { | ||
Injectable, | ||
Injector, | ||
effect, | ||
runInInjectionContext, | ||
} from '@angular/core'; | ||
import { injectQuery } from '../lib/query'; | ||
import { injectQueryClient } from '../lib/query-client'; | ||
import { queryOptions } from '../lib/query-options'; | ||
import { expectTypeOf } from 'expect-type'; | ||
import { map, timer } from 'rxjs'; | ||
import { fakeAsync, flush, TestBed, tick } from '@angular/core/testing'; | ||
|
||
interface Todo { | ||
id: number; | ||
} | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
class TodosService { | ||
#client = injectQueryClient(); | ||
#query = injectQuery(); | ||
|
||
#getTodosOptions = queryOptions({ | ||
queryKey: ['todos'] as const, | ||
queryFn: () => { | ||
return timer(1000).pipe( | ||
map(() => { | ||
return [ | ||
{ | ||
id: 1, | ||
}, | ||
{ id: 2 }, | ||
] as Todo[]; | ||
}), | ||
); | ||
}, | ||
}); | ||
|
||
getTodos() { | ||
return this.#query(this.#getTodosOptions); | ||
} | ||
|
||
getCachedTodos() { | ||
return this.#client.getQueryData(this.#getTodosOptions.queryKey); | ||
} | ||
} | ||
|
||
describe('query', () => { | ||
let service: TodosService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [TodosService], | ||
}); | ||
service = TestBed.inject(TodosService); | ||
}); | ||
|
||
it('should work', fakeAsync(() => { | ||
const spy = jest.fn(); | ||
|
||
const sub = service.getTodos().result$.subscribe((v) => { | ||
spy(v.status); | ||
expectTypeOf(v.data).toEqualTypeOf<Todo[] | undefined>(); | ||
}); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
expect(spy).toHaveBeenCalledWith('pending'); | ||
tick(1000); | ||
flush(); | ||
|
||
expect(spy).toHaveBeenCalledTimes(2); | ||
expect(spy).toHaveBeenCalledWith('success'); | ||
|
||
sub.unsubscribe(); | ||
flush(); | ||
})); | ||
|
||
it('should work with signals', fakeAsync(() => { | ||
const spy = jest.fn(); | ||
|
||
runInInjectionContext(TestBed.inject(Injector), () => { | ||
const result = service.getTodos().result; | ||
expectTypeOf(result().data).toEqualTypeOf<Todo[] | undefined>(); | ||
|
||
effect(() => { | ||
spy(result().status); | ||
}); | ||
}); | ||
|
||
TestBed.flushEffects(); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
expect(spy).toHaveBeenCalledWith('pending'); | ||
tick(1000); | ||
flush(); | ||
TestBed.flushEffects(); | ||
expect(spy).toHaveBeenCalledTimes(2); | ||
expect(spy).toHaveBeenCalledWith('success'); | ||
})); | ||
|
||
it('should be typed', () => { | ||
expectTypeOf(service.getCachedTodos()).toEqualTypeOf<Todo[] | undefined>(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe('intersectResults', () => { | ||
it('should correctly merge and map multiple successful signal queries', () => {}); | ||
|
||
it('should handle error results correctly', () => {}); | ||
|
||
// Additional tests for different scenarios, such as pending, loading states, and mixed results | ||
}); |