-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing unregister method and corresponding tests.
- Loading branch information
1 parent
cfd9d17
commit 9b03347
Showing
6 changed files
with
67 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ const PROPS = [ | |
'log', | ||
'require', | ||
'state', | ||
'unregister', | ||
'_private' | ||
]; | ||
|
||
|
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,44 @@ | ||
const {test, assert, insp} = require('scar'); | ||
const modulejs = require('../loader').modulejs; | ||
|
||
test('modulejs.unregister is function', () => { | ||
assert.equal(typeof modulejs.unregister, 'function'); | ||
}); | ||
|
||
test('modulejs.unregister() throws', () => { | ||
const modjs = modulejs.create(); | ||
assert.throws(() => modjs.unregister(), /id must be string/); | ||
}); | ||
|
||
test('modulejs.unregister() throws if non-string id', () => { | ||
const modjs = modulejs.create(); | ||
assert.throws(() => modjs.unregister(true), /id must be string/); | ||
}); | ||
|
||
test('modulejs.unregister() throws if undefined module', () => { | ||
const modjs = modulejs.create(); | ||
assert.throws(() => modjs.unregister('a'), /id already defined/); | ||
}); | ||
|
||
[ | ||
undefined, | ||
null, | ||
true, | ||
false, | ||
0, | ||
1, | ||
[], | ||
{}, | ||
'' | ||
].forEach(x => { | ||
test(`modulejs.unregister(id, arr, ${insp(x)}) -> .define(id, arr, function () { return ${insp(x)}; })`, () => { | ||
const modjs = modulejs.create(); | ||
const defs = modjs._private.definitions; | ||
const id = 'a'; | ||
assert.equal(modjs.define(id, x), undefined); | ||
|
||
modjs.unregister(id); | ||
assert.equal(typeof defs[id], 'undefined'); | ||
assert.throws(() => modjs.require('a'), /id not defined/); | ||
}); | ||
}); |
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