-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use vitest except where possible and organize tests
- Loading branch information
Showing
7 changed files
with
132 additions
and
143 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
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,21 +1,20 @@ | ||
import { strictEqual } from 'assert' | ||
import { describe, it } from 'vitest' | ||
import { describe, expect, it } from 'vitest' | ||
import { is, string } from '../../src' | ||
|
||
describe('is', () => { | ||
it('valid as helper', () => { | ||
strictEqual(is('valid', string()), true) | ||
expect(is('valid', string())).toBe(true) | ||
}) | ||
|
||
it('valid as method', () => { | ||
strictEqual(string().is('valid'), true) | ||
expect(string().is('valid')).toBe(true) | ||
}) | ||
|
||
it('invalid as helper', () => { | ||
strictEqual(is(42, string()), false) | ||
expect(is(42, string())).toBe(false) | ||
}) | ||
|
||
it('invalid as method', () => { | ||
strictEqual(string().is(42), false) | ||
expect(string().is(42)).toBe(false) | ||
}) | ||
}) |
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,33 @@ | ||
import { describe, it } from 'vitest' | ||
import { CallTracker } from 'assert' | ||
import { any, assert, Context, deprecated } from '../src' | ||
|
||
describe('deprecated', () => { | ||
it('does not log deprecated type if value is undefined', () => { | ||
const tracker = new CallTracker() | ||
const logSpy = buildSpyWithZeroCalls(tracker) | ||
assert(undefined, deprecated(any(), logSpy)) | ||
tracker.verify() | ||
}) | ||
|
||
it('logs deprecated type to passed function if value is present', () => { | ||
const tracker = new CallTracker() | ||
const fakeLog = (value: unknown, ctx: Context) => {} | ||
const logSpy = tracker.calls(fakeLog, 1) | ||
assert('present', deprecated(any(), logSpy)) | ||
tracker.verify() | ||
}) | ||
}) | ||
|
||
/** | ||
* This emulates `tracker.calls(0)`. | ||
* | ||
* `CallTracker.calls` doesn't support passing `0`, therefore we expect it | ||
* to be called once which is our call in this test. This proves that | ||
* the following action didn't call it. | ||
*/ | ||
function buildSpyWithZeroCalls(tracker: CallTracker) { | ||
const logSpy = tracker.calls(1) | ||
logSpy() | ||
return logSpy | ||
} |
Oops, something went wrong.