chore: traits

This commit is contained in:
cha0s 2021-01-06 01:26:56 -06:00
parent fb4bb231f4
commit 3ff8e871f4

View File

@ -0,0 +1,55 @@
import {expect} from 'chai';
import Trait from '../src/trait';
class TestTrait extends Trait {
static defaultParams() {
return {
asd: 'hello',
sdf: 311,
};
}
static defaultState() {
return {
foo: 69,
bar: '420',
};
}
}
it('can set and override default params and state', () => {
const testTrait = new TestTrait({
params: {
asd: 'boo',
},
state: {
bar: 'yee',
},
});
expect(testTrait.toJSON()).to.deep.equal({
params: {
asd: 'boo',
sdf: 311,
},
state: {
bar: 'yee',
foo: 69,
},
});
});
it('tracks state differences', () => {
const testTrait = new TestTrait();
testTrait.state.foo = 420;
expect(testTrait.stateDifferences()).to.deep.equal({
foo: {
old: 69,
value: 420,
},
});
testTrait.markAsClean();
expect(testTrait.stateDifferences()).to.deep.equal({});
});