-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve assertion messages when running expectations (#281)
* tweak Arg generated description * capture stacktraces on each call * add textBuilder and improve assertion messages * bump to node18 * refactor utilities * replace utilities * add rest of constants and stringifies * replace stringify & raw values * support serialization in different contexts * 2.0.0-beta.4
- Loading branch information
1 parent
cf95e14
commit 30c69d9
Showing
19 changed files
with
494 additions
and
182 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
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
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,13 @@ | ||
import test from 'ava' | ||
|
||
import { Substitute } from '../../../src' | ||
|
||
interface Library { } | ||
|
||
test('issue 138: serializes to JSON compatible data', t => { | ||
const lib = Substitute.for<Library>() | ||
const result = JSON.stringify(lib) | ||
|
||
t.true(typeof result === 'string') | ||
t.is(result, '"@Substitute {\\n}"') | ||
}) |
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,39 @@ | ||
import test from 'ava' | ||
import { types } from 'util' | ||
|
||
import { Substitute } from '../../../src' | ||
|
||
interface Library { | ||
subSection: () => string | ||
} | ||
|
||
// Adapted snipped extracted from https://github.com/angular/angular/blob/main/packages/compiler/src/parse_util.ts#L176 | ||
// This is to reproduce the behavior of the Angular compiler. This function tries to extract the id from a reference. | ||
const identifierName = (compileIdentifier: { reference: any } | null | undefined): string | null => { | ||
if (!compileIdentifier || !compileIdentifier.reference) { | ||
return null | ||
} | ||
const ref = compileIdentifier.reference | ||
if (ref['__anonymousType']) { | ||
return ref['__anonymousType'] | ||
} | ||
} | ||
|
||
test('issue 27: mocks should work with Angular TestBed', t => { | ||
const lib = Substitute.for<Library>() | ||
lib.subSection().returns('This is the mocked value') | ||
const result = identifierName({ reference: lib }) | ||
|
||
t.not(result, null) | ||
t.true(types.isProxy(result)) | ||
|
||
const jitId = `jit_${result}` | ||
t.is(jitId, 'jit_property<__anonymousType>: ') | ||
}) | ||
|
||
test('issue 27: subsitute node can be coerced to a primitive value', t => { | ||
const lib = Substitute.for<Library>() | ||
t.true(typeof `${lib}` === 'string') | ||
t.true(typeof (lib + '') === 'string') | ||
t.is(`${lib}`, '@Substitute {\n}') | ||
}) |
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
Oops, something went wrong.