Skip to content

Instantly share code, notes, and snippets.

@kitsonk
Forked from agubler/composeAspectTestCase.js
Last active July 5, 2016 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitsonk/ca950078d4c8bdf985cce8b2b33d31c3 to your computer and use it in GitHub Desktop.
Save kitsonk/ca950078d4c8bdf985cce8b2b33d31c3 to your computer and use it in GitHub Desktop.
Compose Aspect Test Case
'base, initialize, and aspect, twice': function() {
let val = 0;
const stack = [];
const createBase = compose({})
.mixin({
mixin: {
foo: 0,
doFoo: () => {
val++;
stack.push('createBase');
this.foo++;
}
}
});
const createAspectBase = compose({
bar: 'bar'
}, () => {})
.mixin({
mixin: createBase,
aspectAdvice: {
before: {
doFoo() {
val++;
stack.push('createAspectBase');
this.foo++;
}
}
}
});
const create = createAspectBase;
const createFooWidget = create
.mixin({
mixin: createAspectBase,
initialize(instance) {
}
})
.extend({
bar: 'baz'
});
// unused factory that aspects
const createExtendedFooWidget = createFooWidget
.mixin({
aspectAdvice: {
before: {
doFoo() {
val++;
stach.push('createExtendedFooWidget');
this.foo++;
}
}
}
});
const foo = createFooWidget();
foo.doFoo();
assert.strictEqual(foo.foo, 2, 'foo should equal two');
assert.strictEqual(val, 2, 'val should equal two');
assert.deepEqual(stack, [ 'createExtendedFooWidget', 'createAspectBase', 'createBase' ]);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment