Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 879 Bytes

TESTING.md

File metadata and controls

41 lines (29 loc) · 879 Bytes

Testing

Spy update function called by state.update(...)

const state = new Subjective(
    productState, 
    productStateFns,
);

it('should call updateIsLoading update function', () => {

    // spy updateIsLoading update function
    const spy = spyOn(productStateFns, 'updateIsLoading');

    // update state
    state.update(f => f.updateIsLoading, true);

    // check updateIsLoading function has been called
    expect(spy).toHaveBeenCalledWith(jasmine.anything(), true);
});

Test update functions

const state = new Subjective(
    productState, 
    productStateFns,
);

it('should update isLoading property', () => {

    expect(state.snapshot.isLoading).toBe(false);

    // call function
    const updatedState = productStateFns.updateIsLoading(state.snapshot, true);

    expect(updatedState.isLoading).toBe(true);
});