import {expect} from 'chai'; // eslint-disable-next-line import/no-unresolved import {Trait} from '@avocado/traits'; class TestTrait extends Trait { static defaultParams() { return { asd: 'hello', sdf: 311, }; } static defaultState() { return { foo: 69, bar: '420', }; } } // it('optimizes output based on deltas', async () => { // const testTrait = await TestTrait.load({ // params: { // asd: 'boo', // }, // state: { // bar: 'yee', // }, // }); // expect(testTrait.toJSON()).to.deep.equal({ // params: { // asd: 'boo', // }, // state: { // bar: 'yee', // }, // }); // }); 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({}); }); it('can memoize listeners', () => { class ListenerTrait extends Trait { listeners() { return { heard: () => {}, }; } } const testTrait = new ListenerTrait(); const memoized = testTrait.memoizedListeners(); expect(Object.keys(testTrait.listeners())).to.deep.equal(Object.keys(memoized)); expect(testTrait.memoizedListeners()).to.equal(testTrait.memoizedListeners()); });