fix: Prevent PocomathInstance from clobbering its own methods
Resolves #6.
This commit is contained in:
parent
0069597a76
commit
b72212d929
2 changed files with 25 additions and 2 deletions
|
@ -1,13 +1,21 @@
|
|||
import assert from 'assert'
|
||||
import PocomathInstance from '../../src/core/PocomathInstance.mjs'
|
||||
|
||||
const pi = new PocomathInstance('dummy')
|
||||
describe('PocomathInstance', () => {
|
||||
it('creates an instance that can define typed-functions', () => {
|
||||
const pi = new PocomathInstance('dummy')
|
||||
pi.install({'add': {'any,any': [[], (a,b) => a+b]}})
|
||||
pi.install({add: {'any,any': [[], (a,b) => a+b]}})
|
||||
assert.strictEqual(pi.add(2,2), 4)
|
||||
assert.strictEqual(pi.add('Kilroy', 17), 'Kilroy17')
|
||||
assert.strictEqual(pi.add(1, undefined), NaN)
|
||||
assert.throws(() => pi.add(1), TypeError)
|
||||
})
|
||||
|
||||
it('reserves certain function names', () => {
|
||||
assert.throws(
|
||||
() => pi.install({install: {any: [[], x => x]}}), SyntaxError)
|
||||
assert.throws(
|
||||
() => pi.install({_foo: {any: [[], x => x]}}), SyntaxError)
|
||||
})
|
||||
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue