-
-
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.
support serialization in different contexts
- Loading branch information
1 parent
8bc9cde
commit dadeecd
Showing
3 changed files
with
56 additions
and
2 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 |
---|---|---|
@@ -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