JEST TESTING
- mockdata
- Use Mockdata files to store fake data values for the testing
- jest.mock
- take away the functionality of it
- do nothing (we don't have to run everything)
- I don't want to send a notification of sns so did a mock
- Set a global variable of response
- jest.requireActual
- it uses all thd data
- uses actual function
- using only one function there to require it
- most of the times we do only mock whole file but it uses some
- jest.fn
- jest mock function (How many times it was called)
- wrapping our function and add extra unique functions there
- After wrapping this function, we can use them.
- beforeEach
- jest.clearAllMocks()
- This helps with fresh start
- jest.clearAllMocks()
- jest.toHaveBeenCalled()
- toMatchSnapShot()
- If you know what output to be >> check it
- When it's dynamic we use toEqual.
- it
- testing function
- 1st: Title
- 2nd: Function
- describe
- Grouping stuff
- Suggestions: Reading Describe Blocks in JEST library
- expect
- rejects.toThrow(Error)
- Error >> Jest knows
- rejects.toThrow(Error)
- mockImplementation
- Implement the function if it's used after the function
- ex: daos.content.getContent[content name].mockImplementation([OWN FUNCTION])
- arrow function(extra)
- () => ({})
- returns data
- () => ({})
- not.toHaveBeenCalled()
- wants not to be called.
- Data Type
- Date data
- ISO Date
- toIsoDate([date])
- ISO Date
- You can find parameter types in AWS Step Functions >> State Machine
- Date data
- guid()
- Format of the ID (ID is following this pattern)
- property
- constants
- Array
- toContain ([Value])
'Node.js > Jest' 카테고리의 다른 글
[Jest] set, clear and reset mock/spy/stub implementation (0) | 2022.04.16 |
---|---|
[Jest] Jest Mock Functions (0) | 2022.04.15 |
[Node.js] Jest worker encountered 4 child process exceptions, exceeding retry limit (0) | 2022.04.07 |
[JEST] describe (0) | 2022.04.02 |
[Node] Best JavaScript code snippets using joi.date (0) | 2022.04.02 |