/**
 * Creates a spy and stores its reference for later call order checking
 * @param {function} spy
 * @constructor
 */
export function CallOrderChecker(spy) {
    const order = [];
    this.fn = (fn = () => {}) => {
        const wrapper = spy((...args) => {
            order.push(wrapper);
            return fn(...args);
        });
        return wrapper;
    };
    this.precedes = (fn1, fn2) => {
        const fn1idx = order.indexOf(fn1);
        return fn1idx !== -1 && fn1idx < order.indexOf(fn2);
    };
}
