Skip to content

Commit

Permalink
more precise unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jlorenc1986 committed Aug 29, 2024
1 parent 857edb1 commit 6aebca3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
11 changes: 5 additions & 6 deletions src/components/__tests__/Editor.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ test('should render default editor',() => {
expect(el).toBeDefined();
});

test.skip('should render new html when user edits',() => {
render(<Editor />);
const markdown = "mbare"
test('should render new html when user edits',() => {
const {container } = render(<Editor />);
const markdown = "mbare";
const editor = screen.getByRole('textbox');
fireEvent.change(editor, {target:{ value: markdown}})
const preview = screen.getByTitle('editor-preview').nodeValue;
expect(preview).toContain('mbare');
fireEvent.change(editor, {target:{ value: markdown}})
expect(container.getElementsByClassName('preview').item(0)?.innerHTML).toEqual('<p>mbare</p>');
});

10 changes: 5 additions & 5 deletions src/components/__tests__/Preview.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import { render, screen } from "@testing-library/react"; // Importing the render function from the testing library
import Preview from "../Preview"; // Importing the Header component
import { markdownHeaderLevelOne } from '../../constants/test.mocks';

test('should render last markdown from user',() => {
const markdown = "mbare";

render(<Preview md={markdown}/>);
const el = screen.getByText(markdown);
expect(el).toBeDefined();
const markdown = markdownHeaderLevelOne;
const expected = 'A first-level heading';
const {container} = render(<Preview md={markdown}/>);
expect(container.getElementsByTagName('h1').item(0)?.innerHTML).toEqual(expected);
});


1 change: 0 additions & 1 deletion src/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const useLocalStorage = (key: string , defaultValue: string) => {
localStorage.getItem(key) || String(defaultValue)
);
} catch (error) {
console.error(error);
currentValue = defaultValue;
}

Expand Down

0 comments on commit 6aebca3

Please sign in to comment.