-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helpful error when initial data is a non-object
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 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
22 changes: 22 additions & 0 deletions
22
packages/swingset-liveslots/test/virtual-objects/test-empty-data.js
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,22 @@ | ||
import test from 'ava'; | ||
import '@endo/init/debug.js'; | ||
|
||
import { makeFakeVirtualObjectManager } from '../../tools/fakeVirtualSupport.js'; | ||
|
||
test('non-object initial data message', async t => { | ||
const vom = makeFakeVirtualObjectManager(); | ||
// I frequently try to write goodInit and write badInit by | ||
// mistake. It returns undefined, and includes an unused "value:" | ||
// label and a side-effect-free evaluation of a 0 constant. A linter | ||
// might catch this, but it's such an easy mistake to make that the | ||
// VOM's instance maker will catch it and complain. | ||
const goodInit = () => ({ value: 0 }); | ||
// eslint-disable-next-line | ||
const badInit = () => { value: 0 }; | ||
const behavior = {}; | ||
const makeGoodThing = vom.defineKind('goodthing', goodInit, behavior); | ||
const makeBadThing = vom.defineKind('badthing', badInit, behavior); | ||
makeGoodThing(); | ||
const m = s => ({ message: s }); | ||
t.throws(() => makeBadThing(), m(/initial data must be object, not /)); | ||
}); |