How to use the apollo-link-context.setContext.mock function in apollo-link-context

To help you get started, we’ve selected a few apollo-link-context examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / src / __tests__ / index.spec.js View on Github external
jest.isolateModules(() => {
        // Execute index.js.
        require('../');

        // Assert.
        expect(setContext).toHaveBeenCalled();
        const contextCallback = setContext.mock.calls[0][0];
        expect(
            contextCallback(null, { headers: { foo: 'bar' } })
        ).toMatchObject({
            headers: {
                foo: 'bar',
                authorization: ''
            }
        });

        // It includes the authorization header if the signin_token is present.
        getItem.mockReturnValueOnce('blarg');
        expect(contextCallback(null, { headers: {} })).toMatchObject({
            headers: {
                authorization: 'Bearer blarg'
            }
        });

apollo-link-context

An easy way to set and cache context changes for Apollo Link

MIT
Latest version published 4 years ago

Package Health Score

64 / 100
Full package analysis

Similar packages