Skip to content

Commit e6fc121

Browse files
committed
test(pass-style): Relaxations necessary for unsafe hardenTaming test coverage
1 parent 5a996ec commit e6fc121

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

packages/pass-style/test/atom.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ test('isAtom test', t => {
1313
const p = Promise.resolve();
1414
t.false(isAtom(p));
1515
t.throws(() => assertAtom(p), {
16-
message:
17-
'Not even Passable: "[Error: Cannot pass non-frozen objects like \\"[Promise]\\". Use harden()]": "[Promise]"',
16+
// @ts-expect-error isFake is a secret
17+
message: harden.isFake
18+
? 'A "promise" cannot be an atom: "[Promise]"'
19+
: 'Not even Passable: "[Error: Cannot pass non-frozen objects like \\"[Promise]\\". Use harden()]": "[Promise]"',
1820
});
1921

2022
harden(p);

packages/pass-style/test/errors.test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ const { defineProperty } = Object;
1717

1818
test('style of extended errors', t => {
1919
const e1 = Error('e1');
20-
t.throws(() => passStyleOf(e1), {
21-
message: 'Cannot pass non-frozen objects like "[Error: e1]". Use harden()',
22-
});
20+
if (!harden.isFake) {
21+
t.throws(() => passStyleOf(e1), {
22+
message:
23+
'Cannot pass non-frozen objects like "[Error: e1]". Use harden()',
24+
});
25+
}
2326
harden(e1);
2427
t.is(passStyleOf(e1), 'error');
2528

@@ -49,7 +52,7 @@ test('toPassableError, toThrowable', t => {
4952
// Since then, we changed `makeError` to make reasonable effort
5053
// to return a passable error by default. But also added the
5154
// `sanitize: false` option to suppress that.
52-
t.false(Object.isFrozen(e));
55+
t.false(!harden.isFake && Object.isFrozen(e));
5356
t.false(isPassable(e));
5457

5558
// toPassableError hardens, and then checks whether the hardened argument

packages/pass-style/test/far-class-instances.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test('far class instances', t => {
104104
]);
105105
});
106106

107-
test('far class instance hardened empty', t => {
107+
(harden.isFake ? test.skip : test)('far class instance hardened empty', t => {
108108
class FarClass4 extends FarBaseClass {
109109
z = 0;
110110
}

packages/pass-style/test/passStyleOf.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,9 @@ test('Unexpected stack on errors', t => {
485485
err.stack = carrierStack;
486486
harden(err);
487487

488+
// Fake harden does not maintain this invariant, but when passStyleOf senses
489+
// a fake harden, it takes upon itself the obligation to fix the error
490+
// object.
488491
t.throws(() => passStyleOf(err), {
489492
message: 'Passable Error "stack" own property must be a string: {}',
490493
});

0 commit comments

Comments
 (0)