@@ -1584,30 +1584,32 @@ expectPrototype.clone = function () {
1584
1584
1585
1585
expectPrototype . child = function ( ) {
1586
1586
this . _assertTopLevelExpect ( ) ;
1587
- const childExpect = createTopLevelExpect ( {
1588
- assertions : { } ,
1589
- types : [ ] ,
1590
- typeByName : { } ,
1591
- output : this . output . clone ( ) ,
1592
- format : this . outputFormat ( ) ,
1593
- installedPlugins : [ ] ,
1594
- } ) ;
1595
- const parent = ( childExpect . parent = this ) ;
1587
+ const childExpect = createTopLevelExpect (
1588
+ {
1589
+ assertions : { } ,
1590
+ types : [ ] ,
1591
+ typeByName : { } ,
1592
+ output : this . output . clone ( ) ,
1593
+ format : this . outputFormat ( ) ,
1594
+ installedPlugins : [ ] ,
1595
+ } ,
1596
+ this
1597
+ ) ;
1596
1598
1597
1599
childExpect . exportAssertion = function ( testDescription , handler ) {
1598
- parent . addAssertion ( testDescription , handler , childExpect ) ;
1600
+ childExpect . parent . addAssertion ( testDescription , handler , childExpect ) ;
1599
1601
return this ;
1600
1602
} ;
1601
1603
childExpect . exportType = function ( type ) {
1602
1604
if ( childExpect . getType ( type . name ) !== type ) {
1603
1605
childExpect . addType ( type ) ;
1604
1606
}
1605
1607
1606
- parent . addType ( type , childExpect ) ;
1608
+ childExpect . parent . addType ( type , childExpect ) ;
1607
1609
return this ;
1608
1610
} ;
1609
1611
childExpect . exportStyle = function ( name , handler , allowRedefinition ) {
1610
- parent . addStyle (
1612
+ childExpect . parent . addStyle (
1611
1613
name ,
1612
1614
function ( ...args ) {
1613
1615
const childOutput = childExpect . createOutput ( this . format ) ;
@@ -1907,18 +1909,26 @@ Object.defineProperty(expectPrototype, 'argTypes', {
1907
1909
} ,
1908
1910
} ) ;
1909
1911
1910
- function createTopLevelExpect ( {
1911
- assertions = { } ,
1912
- typeByName = { any : anyType } ,
1913
- types = [ anyType ] ,
1914
- output,
1915
- format = magicpen . defaultFormat ,
1916
- installedPlugins = [ ] ,
1917
- } = { } ) {
1912
+ function createTopLevelExpect (
1913
+ {
1914
+ assertions = { } ,
1915
+ typeByName = { any : anyType } ,
1916
+ types = [ anyType ] ,
1917
+ output,
1918
+ format = magicpen . defaultFormat ,
1919
+ installedPlugins = [ ] ,
1920
+ } = { } ,
1921
+ parentExpect
1922
+ ) {
1918
1923
const expect = function ( ...args ) {
1919
1924
return expect . _expect ( new Context ( ) , args ) ;
1920
1925
} ;
1921
- utils . setPrototypeOfOrExtend ( expect , expectPrototype ) ;
1926
+ if ( parentExpect ) {
1927
+ expect . parent = parentExpect ;
1928
+ utils . setPrototypeOfOrExtend ( expect , parentExpect ) ;
1929
+ } else {
1930
+ utils . setPrototypeOfOrExtend ( expect , expectPrototype ) ;
1931
+ }
1922
1932
1923
1933
if ( ! output ) {
1924
1934
output = magicpen ( ) ;
@@ -1928,6 +1938,7 @@ function createTopLevelExpect({
1928
1938
return extend ( expect , {
1929
1939
_topLevelExpect : expect ,
1930
1940
_outputFormat : format ,
1941
+ _frozen : false ,
1931
1942
assertions,
1932
1943
typeByName,
1933
1944
installedPlugins,
0 commit comments