-
Notifications
You must be signed in to change notification settings - Fork 5
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
4 changed files
with
59 additions
and
0 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
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,35 @@ | ||
import { noop } from '@s-libs/micro-dash'; | ||
import { staticTest } from './static-test'; | ||
|
||
let curSpec!: jasmine.SpecResult; | ||
jasmine.getEnv().addReporter({ | ||
specStarted(result) { | ||
curSpec = result; | ||
}, | ||
}); | ||
|
||
describe('testTyping()', () => { | ||
it('satisfies jasmine that the test expects something', () => { | ||
staticTest(noop); | ||
expect(curSpec.passedExpectations.length).toBe(1); | ||
}); | ||
|
||
it('does not execute the code', () => { | ||
staticTest(() => { | ||
fail('this should not run'); | ||
}); | ||
}); | ||
|
||
describe('example from the docs', () => { | ||
function reject<T>(array: T[], predicate: (value: T) => boolean): T[] { | ||
return array.filter((value) => !predicate(value)); | ||
} | ||
|
||
it('requires the predicate type to match the array type', () => { | ||
staticTest(() => { | ||
// @ts-expect-error -- mismatch of number array w/ string function | ||
reject([1, 2, 3], (value: string) => value === '2'); | ||
}); | ||
}); | ||
}); | ||
}); |
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,18 @@ | ||
/** | ||
* Use this when you want to write test code that doesn't actually run, instead relying only on your static tools like Typescript or a linter to raise errors. | ||
* | ||
* ```ts | ||
* function reject<T>(array: T[], predicate: (value: T) => boolean): T[] { | ||
* return array.filter((value) => !predicate(value)); | ||
* } | ||
* | ||
* it('requires the predicate type to match the array type', () => { | ||
* staticTest(() => { | ||
* // @ts-expect-error -- mismatch of number array w/ string function | ||
* reject([1, 2, 3], (value: string) => value === '2'); | ||
* }); | ||
* }); * ``` | ||
*/ | ||
export function staticTest(_test: VoidFunction): void { | ||
expect().nothing(); | ||
} |
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