Skip to content

Commit

Permalink
test(02.렌더링/05): isNodeChanged() 테스트 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
2wndrhs committed Jan 15, 2024
1 parent 4f9cec6 commit 3e2c5e4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions 02. 렌더링/05/isNodeChanged.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isNodeChanged = () => {};

export default isNodeChanged;
59 changes: 59 additions & 0 deletions 02. 렌더링/05/isNodeChanged.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import isNodeChanged from './isNodeChanged';

describe('isNodeChanged', () => {
test('두 노드의 어트리뷰트, 텍스트 컨텐츠가 동일하다면 false 반환', () => {
const node1 = document.createElement('div');
node1.setAttribute('class', 'container');
node1.textContent = 'Hello, world!';

const node2 = document.createElement('div');
node2.setAttribute('class', 'container');
node2.textContent = 'Hello, world!';

expect(isNodeChanged(node1, node2)).toBe(false);
});

test('두 노드가 다른 어트리뷰트를 가지면 true 반환', () => {
const node1 = document.createElement('div');
node1.setAttribute('class', 'container');
node1.textContent = 'Hello, world!';

const node2 = document.createElement('div');
node2.setAttribute('class', 'wrapper');
node2.setAttribute('id', 'myDiv');
node2.textContent = 'Hello, world!';

expect(isNodeChanged(node1, node2)).toBe(true);
});

test('두 노드가 같은 어트리뷰트를 갖지만 어트리뷰트의 값이 다르면 true 반환', () => {
const node1 = document.createElement('div');
node1.setAttribute('class', 'container');
node1.textContent = 'Hello, world!';

const node2 = document.createElement('div');
node2.setAttribute('class', 'wrapper');
node2.textContent = 'Hello, world!';

expect(isNodeChanged(node1, node2)).toBe(true);
});

test('두 노드가 다른 텍스트 컨텐츠를 가지면 true 반환', () => {
const node1 = document.createElement('div');
node1.setAttribute('class', 'container');
node1.textContent = 'Hello, world!';

const node2 = document.createElement('div');
node2.setAttribute('class', 'container');
node2.textContent = 'Hello, GitHub Copilot!';

expect(isNodeChanged(node1, node2)).toBe(true);
});

test('두 노드가 어트리뷰트, 텍스트 컨텐츠를 가지지 않으면 false 반환', () => {
const node1 = document.createElement('div');
const node2 = document.createElement('div');

expect(isNodeChanged(node1, node2)).toBe(false);
});
});

0 comments on commit 3e2c5e4

Please sign in to comment.