I am mocking two functions with with jest.fn:
let first = jest.fn();
let second = jest.fn();
How can I assert that first
called before second
?
What I am looking for is something like sinon's .calledBefore
assertion.
Update I used this simple "temporary" workaround
it( 'should run all provided function in order', () => {
// we are using this as simple solution
// and asked this question here https://stackoverflow.com/q/46066250/2637185
let excutionOrders = [];
let processingFn1 = jest.fn( () => excutionOrders.push( 1 ) );
let processingFn2 = jest.fn( () => excutionOrders.push( 2 ) );
let processingFn3 = jest.fn( () => excutionOrders.push( 3 ) );
let processingFn4 = jest.fn( () => excutionOrders.push( 4 ) );
let data = [ 1, 2, 3 ];
processor( data, [ processingFn1, processingFn2, processingFn3, processingFn4 ] );
expect( excutionOrders ).toEqual( [1, 2, 3, 4] );
} );