-
-
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
74 changed files
with
3,963 additions
and
28 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
projects/spectator/test/**/*.ts | ||
projects/spectator/jest/test/**/*.ts | ||
projects/spectator/vitest/test/**/*.ts | ||
projects/spectator/schematics/**/*.* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
id: vitest-support | ||
title: Vitest Support | ||
--- | ||
|
||
By default, Spectator uses Jasmine for creating spies. If you are using Vitest as test framework instead, you can let Spectator create Vitest-compatible spies. | ||
|
||
## Configuration | ||
|
||
Update your `vite.config.[m]ts` to inline the Spectator package so it gets transformed with Vite before the tests run. | ||
|
||
```ts | ||
export default defineConfig(({ mode }) => ({ | ||
/* ... */ | ||
test: { | ||
/* ... */ | ||
// inline @ngneat/spectator | ||
server: { | ||
deps: { | ||
inline: ['@ngneat/spectator'] | ||
} | ||
} | ||
}, | ||
})); | ||
``` | ||
|
||
## Usage | ||
|
||
Import the functions from `@ngneat/spectator/vitest` instead of `@ngneat/spectator` to use Vitest instead of Jasmine. | ||
|
||
```ts | ||
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest'; | ||
import { AuthService } from './auth.service'; | ||
import { DateService } from './date.service'; | ||
|
||
describe('AuthService', () => { | ||
let spectator: SpectatorService<AuthService>; | ||
const createService = createServiceFactory({ | ||
service: AuthService, | ||
mocks: [DateService] | ||
}); | ||
|
||
beforeEach(() => spectator = createService()); | ||
|
||
it('should not be logged in', () => { | ||
const dateService = spectator.inject<DateService>(DateService); | ||
dateService.isExpired.mockReturnValue(true); | ||
expect(spectator.service.isLoggedIn()).toBeFalsy(); | ||
}); | ||
|
||
it('should be logged in', () => { | ||
const dateService = spectator.inject<DateService>(DateService); | ||
dateService.isExpired.mockReturnValue(false); | ||
expect(spectator.service.isLoggedIn()).toBeTruthy(); | ||
}); | ||
}); | ||
``` |
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({tsconfig: __dirname + '/vitest/tsconfig.spec.json'}), 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'; |
Oops, something went wrong.