Last active
July 5, 2016 14:02
-
-
Save agubler/cc7941a94703844deea6f14dc4084670 to your computer and use it in GitHub Desktop.
Compose Aspect Test Case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'base, initialize, and aspect, twice': function() { | |
let val = 0; | |
const createBase = compose({}) | |
.mixin({ | |
mixin: { | |
foo: 0, | |
doFoo: () => { | |
val++; | |
this.foo++; | |
} | |
} | |
}); | |
const createAspectBase = compose({ | |
bar: 'bar' | |
}, () => {}) | |
.mixin({ | |
mixin: createBase, | |
aspectAdvice: { | |
before: { | |
doFoo() { | |
val++; | |
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++; | |
this.foo++; | |
} | |
} | |
} | |
}); | |
const foo = createFooWidget(); | |
foo.doFoo(); | |
assert.strictEqual(foo.foo, 2, 'foo should equal two'); | |
assert.strictEqual(val, 2, 'val should equal two'); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment