framework icon indicating copy to clipboard operation
framework copied to clipboard

Resource Middleware Mock

Open samends opened this issue 5 years ago • 0 comments

Enhancement Resource middleware mock

As we start using the resource middleware more it could be useful to have a resource mock to use when testing. I'd imagine this could be similar to the createICacheMock that already exists. We could use such a mock when testing out some harder to mock out scenarios such as asynchronous resource calls or when testing for specific values such as when a value is returned bymeta() but isLoading is true.

The resource mock could then be used like this:

describe('MyWidget', () => {
    it('test', async () => {
        const WrappedRoot = wrap('div');
        const baseAssertion = assertion(() => <WrappedRoot>Loading</WrappedRoot>);
        const mockResource = createResourceMock({
                isLoading: true
                meta: { total: 4 }
        });
        const r = renderer(() => <Home />, { middleware: [[createICacheMiddleware(), mockResource]] });
        r.expect(baseAssertion);
    });
});

samends avatar Sep 03 '20 16:09 samends