Skip to content

Commit

Permalink
Merge pull request #5 from icelam/fix-footer-snapshot-test
Browse files Browse the repository at this point in the history
test(footer): fix broken snapshot due to year change
  • Loading branch information
icelam authored Jan 19, 2024
2 parents 029761c + f56abbb commit a640975
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ jobs:
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
verbose: true
5 changes: 3 additions & 2 deletions src/components/Pages/__test__/Footer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import translations from '@locale';
import { mountWithProvider } from '../../../../jest.utils';
import Footer from '../Footer';

const footerCopyrightText = translations.en['footer.copyright'].replace('{currentYear}', '2022');
const footerCopyrightText = translations.en['footer.copyright'].replace('{currentYear}', '2023');
const footerFullText = `${footerCopyrightText}${translations.en['footer.github']}`;
const footerHref = translations.en['footer.github.link'];

const dateSpy = jest.spyOn(global.Date.prototype, 'getFullYear');

describe('Footer', () => {
it('should render', () => {
dateSpy.mockReturnValueOnce(2023);
const wrapper = mountWithProvider(<Footer />);
expect(wrapper.find('div.footer')).toHaveLength(1);
expect(wrapper).toMatchSnapshot();
});

it('should display correct copyright content', () => {
dateSpy.mockReturnValueOnce(2022);
dateSpy.mockReturnValueOnce(2023);
const wrapper = mountWithProvider(<Footer />);
expect(wrapper.find('div.footer').text()).toEqual(footerFullText);
expect(wrapper.find('div.footer a').props().href).toEqual(footerHref);
Expand Down
2 changes: 2 additions & 0 deletions src/components/Pages/__test__/Page.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { mountWithProvider } from '../../../../jest.utils';
import Page from '../Page';

const pageContent = 'Some content here';
const dateSpy = jest.spyOn(global.Date.prototype, 'getFullYear');

describe('Page', () => {
it('should render', () => {
dateSpy.mockReturnValueOnce(2023);
const wrapper = mountWithProvider(<Page><p>Some content here</p></Page>);
expect(wrapper.find('div.content')).toHaveLength(1);
expect(wrapper.find('div.footer')).toHaveLength(1);
Expand Down

0 comments on commit a640975

Please sign in to comment.