-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
Showing
71 changed files
with
3,883 additions
and
25 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -45,3 +45,6 @@ testem.log | |
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# vitest | ||
vite.config.mts.timestamp-*.mjs |
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
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,25 @@ | ||
import '@analogjs/vitest-angular/setup-zone'; | ||
|
||
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; | ||
import { getTestBed } from '@angular/core/testing'; | ||
import { defineGlobalsInjections } from '@ngneat/spectator'; | ||
import { TranslateService } from './test/translate.service'; | ||
import { TranslatePipe } from './test/translate.pipe'; | ||
import { vi } from 'vitest'; | ||
|
||
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); | ||
|
||
defineGlobalsInjections({ | ||
providers: [TranslateService], | ||
declarations: [TranslatePipe], | ||
}); | ||
|
||
beforeEach(() => { | ||
const mockIntersectionObserver = vi.fn(); | ||
mockIntersectionObserver.mockReturnValue({ | ||
observe: () => null, | ||
unobserve: () => null, | ||
disconnect: () => null, | ||
}); | ||
window.IntersectionObserver = mockIntersectionObserver; | ||
}); |
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
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,19 @@ | ||
// <reference types="vitest" /> | ||
import { defineConfig } from 'vite'; | ||
import tsconfigPaths from 'vite-tsconfig-paths'; | ||
|
||
import angular from '@analogjs/vite-plugin-angular'; | ||
|
||
export default defineConfig(({ mode }) => ({ | ||
plugins: [angular(), tsconfigPaths()], | ||
test: { | ||
globals: true, | ||
setupFiles: 'setup-vitest.ts', | ||
environment: 'jsdom', | ||
include: ['vitest/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
reporters: ['default'], | ||
}, | ||
define: { | ||
'import.meta.vitest': mode !== 'production', | ||
}, | ||
})); |
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 @@ | ||
{} |
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 @@ | ||
export { byAltText, byLabel, byPlaceholder, byText, byTextContent, byTitle, byValue, byTestId, byRole } from '@ngneat/spectator'; |
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,64 @@ | ||
export * from 'vitest'; | ||
|
||
interface CustomMatchers<R = unknown> { | ||
toExist(): R; | ||
|
||
toHaveLength(expected: number): R; | ||
|
||
toHaveId(id: string | number): R; | ||
|
||
toHaveClass(className: string | string[], options?: { strict: boolean }): R; | ||
|
||
toHaveAttribute(attr: string | object, val?: string): R; | ||
|
||
toHaveProperty(prop: string | object, val?: string | boolean): R; | ||
|
||
toContainProperty(prop: string | object, val?: string): R; | ||
|
||
toHaveText(text: string | string[] | ((text: string) => boolean), exact?: boolean): R; | ||
|
||
toContainText(text: string | string[] | ((text: string) => boolean), exact?: boolean): R; | ||
|
||
toHaveExactText(text: string | string[] | ((text: string) => boolean), options?: { trim: boolean }): R; | ||
|
||
toHaveExactTrimmedText(text: string | string[] | ((text: string) => boolean)): R; | ||
|
||
toHaveValue(value: string | string[]): R; | ||
|
||
toContainValue(value: string | string[]): R; | ||
|
||
toHaveStyle(style: { [styleKey: string]: any }): R; | ||
|
||
toHaveData({ data, val }: { data: string; val: string }): R; | ||
|
||
toBeChecked(): R; | ||
|
||
toBeIndeterminate(): R; | ||
|
||
toBeDisabled(): R; | ||
|
||
toBeEmpty(): R; | ||
|
||
toBePartial(partial: object): R; | ||
|
||
toBeHidden(): R; | ||
|
||
toBeSelected(): R; | ||
|
||
toBeVisible(): R; | ||
|
||
toBeFocused(): R; | ||
|
||
toBeMatchedBy(selector: string | Element): R; | ||
|
||
toHaveDescendant(selector: string | Element): R; | ||
|
||
toHaveDescendantWithText({ selector, text }: { selector: string; text: string }): R; | ||
|
||
toHaveSelectedOptions(expected: string | string[] | HTMLOptionElement | HTMLOptionElement[]): R; | ||
} | ||
|
||
declare module 'vitest' { | ||
interface Assertion<T = any> extends CustomMatchers<T> {} | ||
interface AsymmetricMatchersContaining extends CustomMatchers {} | ||
} |
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,47 @@ | ||
import { FactoryProvider, AbstractType, Type } from '@angular/core'; | ||
import { installProtoMethods, CompatibleSpy, SpyObject as BaseSpyObject } from '@ngneat/spectator'; | ||
import { Mock, vi } from 'vitest'; | ||
|
||
export type SpyObject<T> = BaseSpyObject<T> & { | ||
[P in keyof T]: T[P] & (T[P] extends (...args: any[]) => infer R ? (R extends (...args: any[]) => any ? Mock<R> : Mock<T[P]>) : T[P]); | ||
}; | ||
|
||
/** | ||
* @publicApi | ||
*/ | ||
export function createSpyObject<T>(type: Type<T> | AbstractType<T>, template?: Partial<Record<keyof T, any>>): SpyObject<T> { | ||
const mock: any = { ...template }; | ||
|
||
installProtoMethods(mock, type.prototype, () => { | ||
const viFn = vi.fn(); | ||
const newSpy: CompatibleSpy = viFn as any; | ||
|
||
newSpy.andCallFake = (fn: Function) => { | ||
viFn.mockImplementation(fn as (...args: any[]) => any); | ||
|
||
return newSpy; | ||
}; | ||
|
||
newSpy.andReturn = (val: any) => { | ||
viFn.mockReturnValue(val); | ||
}; | ||
|
||
newSpy.reset = () => { | ||
viFn.mockReset(); | ||
}; | ||
|
||
return newSpy; | ||
}); | ||
|
||
return mock; | ||
} | ||
|
||
/** | ||
* @publicApi | ||
*/ | ||
export function mockProvider<T>(type: Type<T> | AbstractType<T>, properties?: Partial<Record<keyof T, any>>): FactoryProvider { | ||
return { | ||
provide: type, | ||
useFactory: () => createSpyObject(type, properties), | ||
}; | ||
} |
Oops, something went wrong.