Skip to content

mistersingh179/travel_time

Repository files navigation

Statements Branches Functions Lines
Statements Branches Functions Lines

CircleCI

Requirements:

  • rate limit all API requests
  • travel recommendation API
  • CI
  • Front end

travel recommendation logic:

  • takes source and destination
  • takes dates
  • checks weather
  • checks holdiays

Commands:

DEBUG=test node --inspect=9229 ./node_modules/jest/bin/jest.js --runInBand --watch --verbose

Without --runInBand unable to attach debugger to a running process

Things to Remember:

mocking

  • to mock node modules (e.g. lodash), place the file in __mocks__ and the package will automatically get mocked. There is no need to explicatly call jest.mock(module_name)
  • to mock core node modules (e.g. fs, path etc.), similarly place the file and explicitly call jest.mock('module_name')
  • if automock is set to true, then you dont need to explicitly call jest.mock(module_name)
  • jest.unmock(module_name) is available in case you want the actually implementation but have mocked implementation due to automock being present.
  • jest.getMockFromModule(module_name) cane be used to automatically mock everything in the module. This is useful when you want to override one off thing in the module, but dont want to manually mock everything. In this case just use the autogenerated mocks and modify or add whatever is needed and then export that new thing.
  • jest.requireActual(module_name) gives the actual implementation of the module
  • the __mocks__ directory goes in all directories next to the source code they mock

automatic mock vs manual mock

matchers

  • toBe
  • toEqual
  • toMatch

wow - head scratchers

my last test always fail when i run tests consistently. so its reproducible if i put a breakpoint in this test, it works if i run this test alone, it works it only fails when i run all test and i am not debugging it what gives? turns out its the rate-limiter module i had built. the 429 error code on the response gave it all away.

config

  • jest.setTimeout(100) otherwise default is 5 seconds of waiting for each test to call done.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published