From c40074a0ae586eff04630fd02a954c0ef12ac9d5 Mon Sep 17 00:00:00 2001 From: sabertazimi Date: Sun, 8 Aug 2021 09:41:59 +0800 Subject: [PATCH] test(ArticleComments): add snapshot testing --- .../Article/ArticleComments.test.tsx | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/components/Article/ArticleComments.test.tsx diff --git a/src/components/Article/ArticleComments.test.tsx b/src/components/Article/ArticleComments.test.tsx new file mode 100644 index 000000000..4282b224a --- /dev/null +++ b/src/components/Article/ArticleComments.test.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import { create } from 'react-test-renderer'; +import ArticleComments from './ArticleComments'; + +const commentUrl = 'https://example.com'; + +describe('ArticleComments', () => { + beforeAll(() => { + jest.spyOn(document, 'getElementById').mockImplementation((elementId) => { + return document.createElement(`#${elementId}`); + }); + }); + + afterAll(() => { + (document.getElementById as unknown as jest.SpyInstance).mockRestore(); + }); + + test('should render correctly (snapshot)', () => { + const tree = create().toJSON(); + expect(tree).toMatchSnapshot(); + }); +});