Skip to content

Hw_7#41

Open
xzfantom wants to merge 10 commits intomainfrom
hw_7
Open

Hw_7#41
xzfantom wants to merge 10 commits intomainfrom
hw_7

Conversation

@xzfantom
Copy link
Copy Markdown
Owner

@xzfantom xzfantom commented Aug 9, 2022

tests added

Comment thread src/features/todo/todoSlice.test.ts Outdated
})

test('должен добавить новую задачу', () => {
const previousState = {todos: [], activeCount: 0,};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Используй силу beforeEach для инициализации начального стейта, чтобы не писать его в каждом тесте
DRY))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Там в первом случае начальный стейт отличается от остальных, но ты права, остальные можно выделить в отдельный блок)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(reducer(undefined, { type: undefined })).toEqual({todos: [], activeCount: 0, })
})

в assertion тот же самый prevState :)

const previousState = {todos: [], activeCount: 0,};

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Всё равно не особо соглашусь - начальный стейт используется в 3х тестах из 5, использовать beforeEach не целесообразно. А вот объявить константу имеет смысл)


test('должен добавить новую задачу', () => {
const previousState = {todos: [], activeCount: 0,};
expect(reducer(previousState, todoAdded({data:'data', id:0, done:false}))).toMatchObject({activeCount: 1, todos:[{data:'data', done:false}]});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toEqual здесь будет лучше, поскольку toMatchObject проверяет содержит ли проверяемый объект те свойства, которые ты ему передаешь, но не гарантирует полную идентичность, в отличие от toEqual

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут это сделано намеренно - id будет отличаться.

@xzfantom
Copy link
Copy Markdown
Owner Author

@poulkud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants