Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('returns state of own class if exists', () => {
const instance = {};
pState0(instance); // init private state
expect(pState0.unsafe(instance)).to.equal(pState0(instance))
});
it('throws if no state exists', () => {
it('returns true if exists in own class', () => {
class F {
}
pState0(F); // init private state
expect(pState0.inherited.hasState(F)).to.eql(true);
});
it('returns false if no state exists', () => {
console.log('called on method with ' + methodArguments[0]);
const result: string = next(['goodbye']);
console.log(result);
return 'wrapped=> ' + result
}
const enhanceWithLogMW = functionDecor.middleware(logMW);
const enhanced = enhanceWithLogMW(original);
const result: string = enhanced('hello');
expectLog(
`called on method with hello`,
`goodbye`,
`message printed: goodbye`
);
expect(result).to.eql('wrapped=> message printed: goodbye');
});
it('before and after wraps middleware between features', () => {
const wrapped = ffs1.feature(ffs2.feature(noop));
wrapped();
ffs1.expectToHaveBeenCalledOnce();
ffs2.expectToHaveBeenCalledOnce();
expect(ffs1.beforeSpy.firstCall.calledBefore(ffs2.middlewareBeforeSpy.firstCall), 'ffs1.beforeSpy -> ffs2.middlewareBeforeSpy').to.equal(true);
expect(ffs2.beforeSpy.firstCall.calledBefore(ffs1.middlewareBeforeSpy.firstCall), 'ffs2.beforeSpy -> ffs1.middlewareBeforeSpy').to.equal(true);
expect(ffs1.middlewareAfterSpy.firstCall.calledBefore(ffs2.afterSpy.firstCall), 'ffs1.middlewareAfterSpy -> ffs2.afterSpy').to.equal(true);
expect(ffs2.middlewareAfterSpy.firstCall.calledBefore(ffs1.afterSpy.firstCall), 'ffs2.middlewareAfterSpy -> ffs1.afterSpy').to.equal(true);
});
it("devMode.OFF un-sets global config to dev-mode", () => {
const globalDevMode: boolean | undefined = runInContext(devMode.OFF, () => getGlobalConfig().devMode);
expect(globalDevMode).to.not.be.ok
});
});
it('copies fields of the function', () => {
const func: any = function () {
};
func.foo = 'bar';
const wrapped: any = functionDecor.makeFeature({})(func);
expect(wrapped.foo).to.eql(func.foo);
});
});
lines.forEach((val: string, idx: number) => {
expect(console.log.getCall(idx).args, `call #${idx} argument`).eql([val]);
});
}
it('throws if no state exists', () => {
class F {
}
class G extends F {
}
expect(() => pState0.inherited.unsafe(G)).to.throw();
});
it('returns state of super class if exists', () => {
describe('method forcing', () => {
const spy = sinon.spy();
afterEach("reset console.warn", () => {
spy.reset();
});
function middlewareHook(this: any, next: (...args: any[]) => any, methodArguments: any[]) {
spy();
return next(...methodArguments);
}
function beforeHook(this: any, methodArguments: any[]) {
spy();
return methodArguments;
}
function afterHook(this: any, methodResult: any) {
expectToHaveBeenCalledOnce(msg = '') {
expect(this.beforeSpy, `${msg} : ${this.name}.beforeSpy`).to.have.callCount(1);
expect(this.middlewareBeforeSpy, `${msg} : ${this.name}.middlewareBeforeSpy`).to.have.callCount(1);
expect(this.middlewareAfterSpy, `${msg} : ${this.name}.middlewareAfterSpy`).to.have.callCount(1);
expect(this.afterSpy, `${msg} : ${this.name}.afterSpy`).to.have.callCount(1);
}