40 lines
856 B
JavaScript
40 lines
856 B
JavaScript
import {expect} from 'chai';
|
|
|
|
import {Vector} from '@avocado/math';
|
|
import {Class, compose, EventEmitter} from '@flecks/core';
|
|
|
|
const decorate = compose(
|
|
EventEmitter,
|
|
Vector.Mixin('vector', 'x', 'y', {track: true}),
|
|
);
|
|
|
|
it('can detect mixin changes', () => {
|
|
class Test extends decorate(Class) {
|
|
constructor() {
|
|
super();
|
|
this.passed = 0;
|
|
this.on('xChanged', () => this.passed++);
|
|
this.on('yChanged', () => this.passed++);
|
|
this.on('vectorChanged', () => {
|
|
this.passed *= 2;
|
|
});
|
|
}
|
|
}
|
|
const test = new Test();
|
|
test.vector = [1, 1];
|
|
expect(test.passed)
|
|
.to.equal(4);
|
|
test.x = 1;
|
|
expect(test.passed)
|
|
.to.equal(4);
|
|
test.x = 2;
|
|
expect(test.passed)
|
|
.to.equal(10);
|
|
test.y = 1;
|
|
expect(test.passed)
|
|
.to.equal(10);
|
|
test.y = 2;
|
|
expect(test.passed)
|
|
.to.equal(22);
|
|
});
|