Node.js/Jest

[JEST] Jest Functions with AWS

brightlightkim 2022. 4. 2. 04:32

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.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
  • 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])
    • You can find parameter types in AWS Step Functions >> State Machine
  • guid()
    • Format of the ID (ID is following this pattern)
  • property
    • constants
  • Array
    • toContain ([Value])