chore: traits
This commit is contained in:
parent
fb4bb231f4
commit
3ff8e871f4
55
packages/traits/test/trait.js
Normal file
55
packages/traits/test/trait.js
Normal 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({});
|
||||
});
|
Loading…
Reference in New Issue
Block a user