1.0.3 drop using Reflect, add event emitter to test suite

master
David Kebler 2020-02-20 22:40:56 -08:00
parent ae5b5032ba
commit cf3c23f9e2
4 changed files with 23 additions and 5 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
node_modules node_modules
*.lock

View File

@ -1,6 +1,6 @@
{ {
"name": "@uci-utils/class-merge", "name": "@uci-utils/class-merge",
"version": "1.0.1", "version": "1.0.3",
"description": "Function to merge classes when making an extended class", "description": "Function to merge classes when making an extended class",
"main": "src/merge.js", "main": "src/merge.js",
"scripts": { "scripts": {
@ -26,6 +26,7 @@
"homepage": "https://github.com/uCOMmandIt/uci-utils/class-merge#readme", "homepage": "https://github.com/uCOMmandIt/uci-utils/class-merge#readme",
"devDependencies": { "devDependencies": {
"chai": "^4.2.0", "chai": "^4.2.0",
"chai-eventemitter": "^1.1.1",
"esm": "^3.2.25", "esm": "^3.2.25",
"mocha": "^7.0.1", "mocha": "^7.0.1",
"nodemon": "^2.0.2" "nodemon": "^2.0.2"

View File

@ -19,13 +19,14 @@ export default (base, ...mixins) => {
/* copy properties */ /* copy properties */
let copyProps = (target, source) => { let copyProps = (target, source) => {
Reflect.ownKeys(source) Object.getOwnPropertyNames(source)
.concat(Object.getOwnPropertySymbols(source))
.forEach((prop) => { .forEach((prop) => {
if (typeof prop.match ==='function') { if (typeof prop.match ==='function') {
if (prop.match(/^(?:initializer|constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/)) if (prop.match(/^(?:initializer|constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/))
return return
} }
Reflect.set(target,prop,Reflect.getOwnPropertyDescriptor(source, prop)) Object.defineProperty(target, prop, Object.getOwnPropertyDescriptor(source, prop))
}) })
} }

View File

@ -1,5 +1,9 @@
import merge from '../src/merge.js' import merge from '../src/merge.js'
import { expect } from 'chai' import chai, { expect } from 'chai'
import eventemitter from 'chai-eventemitter'
import { EventEmitter as Emitter } from 'events'
chai.use(eventemitter)
describe('Class Merge', function () { describe('Class Merge', function () {
@ -24,7 +28,7 @@ describe('Class Merge', function () {
set y (v) { this._y = v } set y (v) { this._y = v }
} }
var Rectangle = class Rectangle extends merge(Shape, Colored, ZCoord) {} var Rectangle = class Rectangle extends merge(Shape, Colored, ZCoord, Emitter) {}
var rect = new Rectangle(7, 42) var rect = new Rectangle(7, 42)
rect.z = 1000 rect.z = 1000
@ -36,6 +40,17 @@ describe('Class Merge', function () {
expect(rect.y).to.be.equal(42) expect(rect.y).to.be.equal(42)
expect(rect.z).to.be.equal(1000) expect(rect.z).to.be.equal(1000)
expect(rect.color).to.be.equal('red') expect(rect.color).to.be.equal('red')
})
})
it('Should handle more complex mixin', function () {
// rect.on('test',(data)=>expect(data).to.be.equal('some data'))
// rect.emit('test','some data')
expect(function(){ rect.emit('test', 'some data') }).to.emitFrom(rect, 'test', 'some data')
})
}) })