Skip to content

Instantly share code, notes, and snippets.

@watadarkstar
Created June 4, 2019 20:44
Show Gist options
  • Save watadarkstar/ca6295bd90036385c2ca118ecb4e0449 to your computer and use it in GitHub Desktop.
Save watadarkstar/ca6295bd90036385c2ca118ecb4e0449 to your computer and use it in GitHub Desktop.
import React from 'react';
import { render, cleanup } from 'react-testing-library';
import { AppsNav } from '.';
describe('<AppsNav />', () => {
afterEach(cleanup);
const history = {
listen: jest.fn(),
};
const props = {
classes: {},
location: { pathname: '/' },
navActions: {},
history,
open: false,
};
it('should have a Service Center link', () => {
const { queryAllByText } = render(<AppsNav {...props} />);
expect(queryAllByText('Service Center')).toHaveLength(1);
});
it('should renders as hidden for mobile by default', () => {
window.matchMedia = jest.fn().mockImplementation(query => {
return {
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
};
});
const { getByTestId } = render(<AppsNav {...props} open={false} />);
expect(getByTestId('custom-drawer'));
});
it('renders as shown for mobile when not hidden', () => {
window.matchMedia = jest.fn().mockImplementation(query => {
return {
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
};
});
const { getByTestId } = render(<AppsNav {...props} open />);
expect(getByTestId('custom-drawer-open'));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment