├── .circleci └── config.yml ├── .codeclimate.yml ├── .editorconfig ├── .gitignore ├── .prettierrc ├── .travis.yml ├── .vscode └── launch.json ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── TODO.md ├── jest.config.js ├── jest.setup.js ├── package-lock.json ├── package.json ├── src ├── __mocks_disable__ │ └── axios.ts ├── __utils.ts ├── async │ ├── User.ts │ ├── module.test.ts │ └── module.ts ├── automatic-mocks │ ├── utils.spec.ts │ └── utils.ts ├── beforeEach-with-async-await │ └── index.spec.ts ├── condition-skip-all-test-cases │ └── index.spec.ts ├── import-undefined-issue │ ├── 01 │ │ ├── @types │ │ │ ├── index.js │ │ │ ├── index.ts │ │ │ ├── user.js │ │ │ └── user.ts │ │ └── index.spec.ts │ └── 02 │ │ ├── @types │ │ ├── user.js │ │ └── user.ts │ │ └── index.spec.ts ├── jest-object │ ├── apple.ts │ ├── banana.ts │ ├── grape.ts │ └── index.spec.ts ├── make-stub-for-generator │ ├── index.js │ └── index.spec.js ├── mock-and-destructuring │ ├── aws-sdk.ts │ ├── main.spec.ts │ └── main.ts ├── mock-es6-class │ ├── Component.ts │ ├── LocationDAOImpl.ts │ ├── db.ts │ ├── mock-class-getter │ │ └── index.spec.ts │ └── mock-specific-method │ │ └── index.spec.ts ├── mock-function │ ├── callback │ │ ├── index.spec.ts │ │ ├── toBeTested.ts │ │ └── xyz.ts │ ├── cmd-export-class │ │ ├── module.test.ts │ │ └── module.ts │ ├── cmd │ │ ├── module.js │ │ └── module.test.js │ ├── es6-module-1 │ │ ├── module.test.ts │ │ └── module.ts │ ├── es6-module-2 │ │ ├── module.test.ts │ │ └── module.ts │ ├── es6-module-3 │ │ ├── module.test.ts │ │ └── module.ts │ ├── es6-module-4 │ │ ├── module.test.ts │ │ └── module.ts │ ├── es6-module-5 │ │ ├── interfaces.ts │ │ ├── module.test.ts │ │ └── module.ts │ ├── get-started │ │ └── index.spec.ts │ └── with-closure │ │ ├── index.spec.ts │ │ └── index.ts ├── mock-http-request │ ├── __mocks__ │ │ └── myRequest.ts │ ├── __tests__ │ │ ├── user.model.spec.ts │ │ └── user.service.spec.ts │ ├── interfaces │ │ └── user.ts │ ├── myRequest.ts │ ├── user.model.ts │ └── user.service.ts ├── mock-module │ ├── axios │ │ ├── index.spec.ts │ │ └── index.ts │ ├── demo-1 │ │ ├── LocationDAOImpl.ts │ │ ├── LocationService.ts │ │ ├── __mocks__ │ │ │ └── LocationDAOImpl.ts │ │ ├── __tests__ │ │ │ ├── full-mock.spec.ts │ │ │ └── mocks.spec.ts │ │ └── db.ts │ └── node-fetch │ │ ├── index.spec.ts │ │ └── index.ts ├── mock-ts-namespace │ ├── index.spec.ts │ └── index.ts ├── multiple-beforeAll │ ├── a.spec.ts │ ├── b.spec.ts │ ├── c.spec.ts │ └── envVars.ts ├── open-handle-potentially-keeping-Jest-from-exiting │ ├── UserService.ts │ ├── __tests__ │ │ └── UserService.spec.ts │ └── pubsub.ts ├── react-enzyme-examples │ ├── 01-quick-start │ │ ├── Foo.spec.tsx │ │ └── Foo.tsx │ └── 02-react-hooks │ │ ├── index.spec.tsx │ │ └── index.tsx ├── react-test-renderer-examples │ ├── 01-quick-start │ │ └── index.tsx │ ├── 02-react-sfc │ │ ├── index.spec.tsx │ │ └── index.tsx │ └── 03-react-hooks │ │ └── useRef │ │ ├── index.spec.tsx │ │ └── index.tsx ├── stackoverflow │ ├── 36082197 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 38129774 │ │ ├── ajax.spec.ts │ │ └── ajax.ts │ ├── 42137891 │ │ ├── AuthService.spec.ts │ │ ├── AuthService.ts │ │ └── auth0 │ │ │ ├── WebAuth.ts │ │ │ └── index.ts │ ├── 42676657 │ │ ├── article-api.js │ │ └── article-api.spec.js │ ├── 43292263 │ │ ├── main.spec.ts │ │ ├── main.ts │ │ ├── other.spec.ts │ │ ├── other.ts │ │ ├── sharedMocks.ts │ │ └── someModule.ts │ ├── 44922162 │ │ ├── index.js │ │ └── index.test.js │ ├── 45062447 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 45702292 │ │ ├── chai.setup.js │ │ └── index.test.js │ ├── 45918386 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 46152048 │ │ ├── index.js │ │ ├── index.test.js │ │ └── someAsyncFunction.js │ ├── 46213271 │ │ ├── index.jsx │ │ └── index.test.jsx │ ├── 46431638 │ │ ├── globals.ts │ │ ├── index.test.ts │ │ └── index.ts │ ├── 46437290 │ │ ├── utils.js │ │ └── utils.spec.js │ ├── 46783353 │ │ └── index.tsx │ ├── 46911799 │ │ ├── index-2.spec.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 47093028 │ │ ├── MyAnotherClass.ts │ │ ├── MyClass.test.ts │ │ └── MyClass.ts │ ├── 47128513 │ │ ├── index.js │ │ └── index.test.js │ ├── 47412169 │ │ ├── Translate.ts │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 47493126 │ │ ├── TodoSearch.spec.tsx │ │ └── TodoSearch.tsx │ ├── 47531051 │ │ ├── __mocks__ │ │ │ └── api.ts │ │ ├── api.test.ts │ │ └── api.ts │ ├── 47540126 │ │ ├── app.spec.ts │ │ ├── app.ts │ │ └── moduleA.ts │ ├── 47560126 │ │ ├── actionCreators.spec.ts │ │ ├── actionCreators.ts │ │ └── showErrorAlert.ts │ ├── 47587358 │ │ ├── user.js │ │ ├── userRepo.js │ │ ├── userRepo.test.js │ │ └── userTable.js │ ├── 47704309 │ │ ├── actions.js │ │ ├── reducer.js │ │ └── reducer.test.js │ ├── 47865190 │ │ ├── app.js │ │ └── app.test.js │ ├── 47921226 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 47953161 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 48006588 │ │ ├── buildUrl.js │ │ ├── buildUrl.spec.js │ │ └── config.js │ ├── 48146038 │ │ ├── action.test.ts │ │ └── action.ts │ ├── 48888509 │ │ ├── index.js │ │ └── index.test.js │ ├── 49146453 │ │ ├── index.test.tsx │ │ └── index.tsx │ ├── 49824394 │ │ ├── actionCreators.spec.ts │ │ └── actionCreators.ts │ ├── 50085505 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 50217960 │ │ ├── Foo.ts │ │ ├── SomeClass.ts │ │ └── index.spec.ts │ ├── 50540892 │ │ ├── foo.test.tsx │ │ └── foo.tsx │ ├── 50912106 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 51275648 │ │ ├── Apple.js │ │ └── Apple.spec.js │ ├── 51566816 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 51983850 │ │ ├── actionTypes.ts │ │ ├── order.spec.ts │ │ └── order.ts │ ├── 52025257 │ │ ├── actionCreators.spec.ts │ │ ├── actionCreators.ts │ │ ├── followApi.ts │ │ └── httpServise.ts │ ├── 52075711 │ │ ├── A.spec.ts │ │ ├── A.ts │ │ ├── B.ts │ │ └── util.ts │ ├── 52172531 │ │ ├── react-native-touch-id.spec.ts │ │ └── react-native-touch-id.ts │ ├── 52326039 │ │ ├── dropdown-data-actions.spec.ts │ │ ├── dropdown-data-actions.ts │ │ └── year-groups-selectors.ts │ ├── 52550469 │ │ ├── auth.test.ts │ │ ├── auth.ts │ │ └── firebase.ts │ ├── 52673113 │ │ ├── __mocks__ │ │ │ └── checkNetwork.ts │ │ ├── checkNetwork.ts │ │ ├── errors.ts │ │ ├── postRequests.test.ts │ │ └── postRequests.ts │ ├── 52729002 │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── interfaces │ │ │ └── index.ts │ │ └── models │ │ │ ├── UserModel.ts │ │ │ └── index.ts │ ├── 52831401 │ │ ├── index.js │ │ └── index.spec.js │ ├── 52845000 │ │ ├── anotherFunction.js │ │ ├── myFunction.js │ │ └── myFunction.spec.js │ ├── 52887470 │ │ ├── Button.spec.tsx │ │ └── Button.tsx │ ├── 52899150 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 52944804 │ │ ├── Button.tsx │ │ ├── FormContainer.tsx │ │ ├── Input.tsx │ │ ├── SearchForm.spec.tsx │ │ └── SearchForm.tsx │ ├── 53352420 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 53788454 │ │ ├── CustomComponent.tsx │ │ ├── __snapshots__ │ │ │ └── main.spec.tsx.snap │ │ ├── main.spec.tsx │ │ └── main.tsx │ ├── 53889291 │ │ ├── functions.js │ │ └── functions.spec.js │ ├── 53920812 │ │ ├── routes.js │ │ ├── server.js │ │ └── server.spec.js │ ├── 53934331 │ │ ├── authService.spec.ts │ │ └── authService.ts │ ├── 54230886 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 54340281 │ │ ├── actionCreators.ts │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 54360588 │ │ ├── dynamodb.js │ │ └── dynamodb.test.js │ ├── 54393006 │ │ ├── index.spec.ts │ │ ├── index.ts │ │ └── react-native.ts │ ├── 54456606 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 54555039 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 54587960 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── actionCreators.ts │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 54622746 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 54693637 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 54729837 │ │ ├── third_party_module.js │ │ ├── util.js │ │ └── util.spec.js │ ├── 54794512 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 55011802 │ │ ├── index.jsx │ │ └── index.spec.jsx │ ├── 55049522 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 55127764 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 55228389 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 55302401 │ │ └── app.js │ ├── 55766433 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 55767756 │ │ ├── TableName.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 55787988 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 55789099 │ │ ├── DashboardChart.spec.tsx │ │ ├── DashboardChart.tsx │ │ ├── custom-http-client.ts │ │ └── getIntentsSince.ts │ ├── 55828418 │ │ ├── myComponent.spec.tsx │ │ ├── myComponent.tsx │ │ └── service.ts │ ├── 55838798 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 55936794 │ │ ├── discount.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 55966013 │ │ ├── UnderTest.spec.ts │ │ └── UnderTest.ts │ ├── 55966274 │ │ ├── actionCreators.spec.ts │ │ ├── actionCreators.ts │ │ └── types.ts │ ├── 55986832 │ │ ├── server.js │ │ └── server.test.js │ ├── 56011077 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 56014527 │ │ ├── app.js │ │ ├── app.spec.js │ │ └── work.js │ ├── 56132437 │ │ └── index.ts │ ├── 56238887 │ │ ├── PolicyModels.ts │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 56281185 │ │ ├── DataService.ts │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 56354252 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 56379585 │ │ ├── mutations.spec.ts │ │ └── mutations.ts │ ├── 56410688 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 56425230 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 56446543 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 56453372 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 56482707 │ │ ├── StudentServices.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 56546760 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 56635460 │ │ ├── index.js │ │ └── index.spec.js │ ├── 56639450 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 56674440 │ │ ├── Models.ts │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 56730186 │ │ ├── privateRoute.test.tsx │ │ └── privateRoute.tsx │ ├── 56735795 │ │ ├── server.spec.ts │ │ └── server.ts │ ├── 56739670 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 56821395 │ │ ├── index.js │ │ └── index.spec.js │ ├── 56847385 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 56847791 │ │ ├── serverErrorResponseUtil.ts │ │ ├── validateUniqueName.spec.ts │ │ └── validateUniqueName.ts │ ├── 56924299 │ │ ├── HttpResponse.ts │ │ ├── bcrypt.ts │ │ ├── config.ts │ │ ├── dbSessionModule.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ └── signupModule.ts │ ├── 56942805 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 56960035 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 56961691 │ │ ├── index.spec.ts │ │ ├── index.ts │ │ └── shared │ │ │ └── user │ │ │ └── index.ts │ ├── 57087200 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57088724 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57092154 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57154476 │ │ ├── HeaderBar.test.tsx │ │ └── HeaderBar.tsx │ ├── 57172774 │ │ ├── service.spec.ts │ │ └── service.ts │ ├── 57248527 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 57283122 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57290601 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 57322103 │ │ ├── index.jsx │ │ └── index.spec.jsx │ ├── 57353897 │ │ ├── request.spec.ts │ │ └── request.ts │ ├── 57353993 │ │ ├── app.js │ │ └── app.test.js │ ├── 57394312 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57409561 │ │ ├── __snapshots__ │ │ │ └── index.spec.ts.snap │ │ ├── expressService.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57410473 │ │ ├── OriginalClass.spec.ts │ │ └── OriginalClass.ts │ ├── 57416715 │ │ ├── index.js │ │ └── index.spec.js │ ├── 57423762 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57428542 │ │ ├── Agent.ts │ │ ├── extractPayloadDates.spec.ts │ │ └── extractPayloadDates.ts │ ├── 57461614 │ │ ├── index.spec.ts │ │ ├── index.ts │ │ └── socket.ts │ ├── 57492604 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57494989 │ │ ├── __mocks__ │ │ │ └── loadDataFromLocalStorage.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ └── loadDataFromLocalStorage.ts │ ├── 57515192 │ │ ├── Db.ts │ │ ├── example.spec.ts │ │ └── example.ts │ ├── 57565053 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57565585 │ │ ├── app.test.ts │ │ └── app.ts │ ├── 57585620 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57589104 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57593767 │ │ ├── auth.js │ │ └── utils.js │ ├── 57614415 │ │ ├── UploadHandler.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57624975 │ │ ├── a.spec.ts │ │ ├── a.ts │ │ ├── one.ts │ │ ├── three.ts │ │ └── two.ts │ ├── 57649917 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57660437 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ ├── index.tsx │ │ └── requestService.ts │ ├── 57671298 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57673447 │ │ ├── ActivationUI.tsx │ │ ├── ExternalLandingPageUtil.ts │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 57674824 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 57704755 │ │ ├── apiClient.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57712713 │ │ ├── index.js │ │ ├── index.spec.js │ │ ├── util.js │ │ └── viewer.js │ ├── 57719741 │ │ ├── client.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57730120 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57730153 │ │ ├── actionCreators.spec.ts │ │ └── actionCreators.ts │ ├── 57775960 │ │ ├── __mocks__ │ │ │ └── someService.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── index2.spec.ts │ │ └── someService.ts │ ├── 57778786 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 57797518 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 57802233 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57805917 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 57810999 │ │ ├── downloadCSV.spec.ts │ │ └── downloadCSV.ts │ ├── 57811289 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57835066 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57847401 │ │ ├── index.spec.tsx │ │ ├── index.tsx │ │ └── testfunction.ts │ ├── 57850379 │ │ ├── index.js │ │ └── index.spec.js │ ├── 57897576 │ │ ├── app.js │ │ └── app.test.js │ ├── 57931751 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57942218 │ │ ├── ProductListItem.tsx │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 57943619 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 57960039 │ │ ├── service.spec.ts │ │ └── service.ts │ ├── 57963177 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 57992553 │ │ ├── ExampleService.ts │ │ ├── __tests__ │ │ │ └── ExampleService.spec.ts │ │ ├── axiosConfig.ts │ │ └── interfaces │ │ │ └── Approval.ts │ ├── 58012116 │ │ ├── actionCreators.spec.ts │ │ └── actionCreators.ts │ ├── 58028571 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58048849 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── electron.ts │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58049595 │ │ ├── First.spec.tsx │ │ ├── First.tsx │ │ └── TelemetryFramework.tsx │ ├── 58059957 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58073589 │ │ ├── dependency-service-instance.ts │ │ ├── dependency-service.ts │ │ ├── my-service.spec.ts │ │ └── my-service.ts │ ├── 58081822 │ │ └── index.spec.ts │ ├── 58082922 │ │ ├── api.ts │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58085900 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58107885 │ │ ├── client.ts │ │ ├── main.spec.ts │ │ └── main.ts │ ├── 58110463 │ │ ├── ajaxService.ts │ │ ├── example.spec.tsx │ │ ├── example.tsx │ │ └── service.ts │ ├── 58136380 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58238433 │ │ └── index.spec.ts │ ├── 58239972 │ │ ├── Vue.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58244855 │ │ ├── .tmp │ │ │ └── genericCsv.csv │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58258206 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58264344 │ │ └── index.spec.ts │ ├── 58273544 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58306745 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58310060 │ │ └── index.spec.ts │ ├── 58357043 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58365044 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58396438 │ │ ├── actionCreator.spec.ts │ │ ├── actionCreator.ts │ │ └── apiCall.ts │ ├── 58413956 │ │ ├── anotherFile.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58445250 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58454044 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58457004 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58480169 │ │ ├── sampleTest.ts │ │ └── sampleTestSuite.test.ts │ ├── 58484558 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58489318 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58519556 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58521281 │ │ ├── index.spec.tsx │ │ ├── index.tsx │ │ └── utils.ts │ ├── 58524183 │ │ ├── NotFound.jsx │ │ └── NotFound.test.jsx │ ├── 58530865 │ │ ├── a.spec.ts │ │ ├── a.ts │ │ └── utils.ts │ ├── 58548563 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58554920 │ │ ├── simple.spec.tsx │ │ └── simple.tsx │ ├── 58561765 │ │ ├── a.js │ │ ├── a.spec.js │ │ └── b.js │ ├── 58562583 │ │ ├── SignOutButton.tsx │ │ ├── firebase.ts │ │ └── setupTests.ts │ ├── 58569731 │ │ ├── auth.test.js │ │ └── server.js │ ├── 58585527 │ │ ├── index.spec.tsx │ │ ├── index.tsx │ │ └── window.setup.js │ ├── 58595518 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58603653 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58610112 │ │ ├── sampleComponent.test.tsx │ │ └── sampleComponent.tsx │ ├── 58623194 │ │ ├── dataService.js │ │ ├── index.js │ │ └── index.spec.js │ ├── 58625148 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58642342 │ │ └── FileUpload.tsx │ ├── 58644737 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58648463 │ │ ├── contants │ │ │ └── svc.ts │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58648691 │ │ ├── index.js │ │ └── index.spec.js │ ├── 58651192 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58652312 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58663681 │ │ └── api.tests.js │ ├── 58674975 │ │ ├── index.spec.ts │ │ ├── index.ts │ │ └── scrape.ts │ ├── 58692161 │ │ ├── api.js │ │ ├── api.spec.js │ │ ├── controller.js │ │ ├── controller.spec.js │ │ └── db.js │ ├── 58696477 │ │ ├── index.js │ │ └── index.spec.js │ ├── 58701700 │ │ ├── index.js │ │ └── index.spec.js │ ├── 58710736 │ │ ├── index.js │ │ └── index.spec.js │ ├── 58727351 │ │ ├── ddb.js │ │ ├── tools.js │ │ └── tools.spec.js │ ├── 58741410 │ │ ├── AuthService.js │ │ ├── Tester.jsx │ │ └── Tester.spec.jsx │ ├── 58746881 │ │ ├── filters-state.helper.ts │ │ └── search-view-state.helper.ts │ ├── 58748367 │ │ ├── index.jsx │ │ └── index.spec.jsx │ ├── 58757332 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58758771 │ │ ├── v1 │ │ │ ├── constants.ts │ │ │ ├── index.spec.ts │ │ │ └── index.ts │ │ └── v2 │ │ │ ├── constants.ts │ │ │ ├── index.spec.ts │ │ │ └── index.ts │ ├── 58775089 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58786973 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58793061 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58803026 │ │ ├── action.js │ │ └── action.spec.js │ ├── 58807874 │ │ ├── index.js │ │ └── index.spec.js │ ├── 58808783 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58810079 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58815471 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58818402 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 58820204 │ │ ├── index.jsx │ │ └── index.spec.jsx │ ├── 58826185 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 58828255 │ │ └── index.spec.ts │ ├── 58842143 │ │ ├── api.js │ │ └── api.test.js │ ├── 58859904 │ │ └── notifications.ts │ ├── 58877501 │ │ ├── index.jsx │ │ └── index.spec.tsx │ ├── 58948797 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 59024742 │ │ ├── customer.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 59027031 │ │ ├── index.js │ │ ├── index.spec.js │ │ └── unzipper.js │ ├── 59028966 │ │ ├── __snapshots__ │ │ │ └── index.spec.tsx.snap │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 59035729 │ │ ├── UserService.ts │ │ ├── auth.test.ts │ │ └── auth.ts │ ├── 59057693 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 59062023 │ │ └── index.ts │ ├── 59068158 │ │ ├── server.js │ │ └── server.test.js │ ├── 59084313 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 59090082 │ │ ├── server.js │ │ ├── server.test.js │ │ └── start.js │ ├── 59108624 │ │ ├── index.js │ │ └── index.spec.js │ ├── 59146770 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 59148901 │ │ ├── index.js │ │ └── index.spec.js │ ├── 59150545 │ │ ├── index.js │ │ ├── index.spec.js │ │ └── third-party.js │ ├── 59162138 │ │ └── index.tsx │ ├── 59163345 │ │ ├── asmConfigService.test.ts │ │ ├── asmConfigService.ts │ │ └── types.ts │ ├── 59168766 │ │ ├── index.js │ │ └── index.spec.js │ ├── 59169619 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 59187875 │ │ ├── asmConfigService.ts │ │ ├── myService.test.ts │ │ └── myService.ts │ ├── 59197574 │ │ ├── index.spec.tsx │ │ ├── index.tsx │ │ └── reducer.ts │ ├── 59198002 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 59207566 │ │ ├── ModelUtility.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 59208419 │ │ ├── App.js │ │ ├── App.test.js │ │ └── Utils.js │ ├── 59233898 │ │ ├── index.js │ │ └── index.spec.js │ ├── 59235639 │ │ ├── Employee.test.ts │ │ ├── config │ │ │ └── IDBConnection.ts │ │ ├── controllers │ │ │ └── employeeController.ts │ │ └── services │ │ │ └── employeeService.ts │ ├── 59241777 │ │ ├── api │ │ │ └── getProducts.ts │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 59250480 │ │ ├── pdf.js │ │ └── pdf.test.js │ ├── 59261385 │ │ ├── a.js │ │ └── a.test.js │ ├── 59266532 │ │ ├── ScriptTag.test.ts │ │ └── ScriptTag.ts │ ├── 59281612 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 59298693 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 59299691 │ │ ├── AggregationPage.test.jsx │ │ ├── AggregationPageContent.jsx │ │ └── _utility.js │ ├── 59310993 │ │ ├── ScriptTag.test.ts │ │ └── ScriptTag.ts │ ├── 59311260 │ │ ├── helper.js │ │ └── helper.test.js │ ├── 59311270 │ │ ├── functions.test.ts │ │ └── functions.ts │ ├── 59315311 │ │ ├── BookService.test.ts │ │ └── BookService.ts │ ├── 59317049 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 59319610 │ │ ├── main.test.ts │ │ └── main.ts │ ├── 59330476 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 59352068 │ │ ├── testClass.test.js │ │ └── testClass.js │ ├── 59366107 │ │ ├── Book-logger.ts │ │ ├── main.test.ts │ │ └── main.ts │ ├── 59368499 │ │ ├── index.test.tsx │ │ └── index.tsx │ ├── 59371450 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 59379085 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 59383743 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 59388359 │ │ ├── logger.js │ │ └── logger.test.js │ ├── 59416347 │ │ ├── users.js │ │ └── users.test.js │ ├── 59423508 │ │ ├── main.js │ │ └── main.test.js │ ├── 59426030 │ │ ├── app.js │ │ ├── token-store.js │ │ └── users.test.js │ ├── 59430114 │ │ └── index.ts │ ├── 59431651 │ │ ├── _validation │ │ │ └── report.js │ │ ├── ctrl.js │ │ ├── ctrl.test.js │ │ └── models │ │ │ └── report.js │ ├── 59448015 │ │ ├── useResponsive.spec.ts │ │ └── useResponsive.ts │ ├── 59455504 │ │ ├── index.jsx │ │ └── index.spec.jsx │ ├── 59459690 │ │ ├── add.js │ │ ├── add.test.js │ │ └── validator.js │ ├── 59463491 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 59463875 │ │ ├── mailgun.test.ts │ │ └── mailgun.ts │ ├── 59466379 │ │ ├── sample.test.ts │ │ └── sample.ts │ ├── 59475724 │ │ ├── index.jsx │ │ └── index.spec.jsx │ ├── 59481051 │ │ ├── index.jsx │ │ └── index.spec.jsx │ ├── 59494359 │ │ ├── index.jsx │ │ └── index.spec.jsx │ ├── 59495121 │ │ ├── getAnswers.js │ │ └── getAnswers.test.js │ ├── 59508494 │ │ ├── controller.js │ │ ├── controller.test.js │ │ └── service.js │ ├── 59515767 │ │ ├── index.js │ │ └── index.spec.js │ ├── 59520741 │ │ ├── main.test.js │ │ └── test_file.js │ ├── 59540432 │ │ ├── handler.js │ │ ├── index.js │ │ └── index.spec.js │ ├── 59566126 │ │ ├── service.js │ │ └── service.test.js │ ├── 59581721 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 59586141 │ │ ├── api.js │ │ ├── api.test.jsx │ │ └── app.jsx │ ├── 59591410 │ │ ├── apiservice.js │ │ ├── group.js │ │ └── group.test.js │ ├── 59627009 │ │ ├── adc.service.ts │ │ ├── sop3login.ts │ │ ├── work.test.ts │ │ └── work.ts │ ├── 59650697 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 59675724 │ │ ├── index.spec.tsx │ │ └── index.tsx │ ├── 59698218 │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 59715038 │ │ ├── index.test.tsx │ │ ├── index.tsx │ │ └── templateService.ts │ ├── 59731700 │ │ ├── main.test.ts │ │ └── main.ts │ ├── 59735993 │ │ ├── __mocks__ │ │ │ └── api_59735993.js │ │ ├── api_59735993.js │ │ ├── app.jsx │ │ └── app.test.jsx │ ├── 59737707 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 59741487 │ │ ├── index.jsx │ │ └── index.test.jsx │ ├── 59751925 │ │ ├── index.js │ │ └── index.test.js │ ├── 59754838 │ │ ├── actionCreator.ts │ │ ├── actionTypes.ts │ │ ├── api.middleware.test.ts │ │ └── api.middleware.ts │ ├── 59759511 │ │ ├── index.test.tsx │ │ └── index.tsx │ ├── 59770174 │ │ ├── index.enzyme.test.tsx │ │ ├── index.tsx │ │ └── throttle.test.ts │ ├── 59771991 │ │ ├── index.jsx │ │ └── index.test.jsx │ ├── 59796811 │ │ ├── actions.test.ts │ │ ├── actions.ts │ │ └── api.ts │ ├── 59796928 │ │ ├── app.jsx │ │ ├── app.test.jsx │ │ └── table.jsx │ ├── 59799196 │ │ ├── login.jsx │ │ └── login.test.jsx │ ├── 59810802 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 59825407 │ │ ├── authenticationService.ts │ │ ├── privateRoute.test.tsx │ │ └── privateRoute.tsx │ ├── 59831697 │ │ ├── api.js │ │ ├── file.js │ │ ├── file.test.js │ │ └── nodeModule.js │ ├── 59833555 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 59853199 │ │ ├── api.ts │ │ ├── item.tsx │ │ ├── itemList.test.tsx │ │ ├── itemList.tsx │ │ └── listModule.ts │ ├── 59857333 │ │ ├── logger.test.ts │ │ └── logger.ts │ ├── 59867716 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 59871106 │ │ ├── index.test.ts │ │ ├── index.ts │ │ └── student.service.ts │ ├── 59873406 │ │ ├── index.js │ │ └── index.test.js │ ├── 59877312 │ │ ├── index.js │ │ └── index.test.js │ ├── 59886364 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 59892259 │ │ └── index.tsx │ ├── 59927917 │ │ ├── index.test.ts │ │ ├── index.ts │ │ └── recommendCards.ts │ ├── 59934084 │ │ ├── index.jsx │ │ └── index.test.jsx │ ├── 59942177 │ │ ├── index.js │ │ └── index.test.js │ ├── 59947808 │ │ ├── index.js │ │ └── index.test.js │ ├── 59980692 │ │ ├── index.test.tsx │ │ └── index.tsx │ ├── 60003884 │ │ ├── index.js │ │ └── index.test.js │ ├── 60008679 │ │ ├── index.js │ │ ├── index.test.js │ │ └── some-service.js │ ├── 60014903 │ │ ├── index.js │ │ └── index.test.js │ ├── 60018953 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63253476 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63369776 │ │ ├── index.js │ │ └── index.test.js │ ├── 63401335 │ │ ├── index.js │ │ └── index.test.js │ ├── 63478184 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63484075 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63531414 │ │ ├── index.test.ts │ │ ├── index.ts │ │ └── validator.ts │ ├── 63570675 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63605899 │ │ ├── Join.test.tsx │ │ └── Join.tsx │ ├── 63607465 │ │ └── Page │ │ │ ├── Children │ │ │ ├── Child.js │ │ │ └── index.js │ │ │ ├── Parent.js │ │ │ ├── Parent.spec.js │ │ │ └── __snapshots__ │ │ │ └── Parent.spec.js.snap │ ├── 63615134 │ │ └── index.test.ts │ ├── 63640360 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63676669 │ │ └── script.js │ ├── 63748243 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63797764 │ │ ├── classA.ts │ │ ├── classB.ts │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63811749 │ │ ├── fn.test.ts │ │ └── fn.ts │ ├── 63820836 │ │ ├── exec.ts │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63863647 │ │ ├── my-class.test.ts │ │ └── my-class.ts │ ├── 63955435 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63957885 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63957901 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 63981693 │ │ ├── api.ts │ │ └── index.tsx │ ├── 64003254 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 64026812 │ │ ├── index.test.tsx │ │ └── index.tsx │ ├── 64039945 │ │ ├── index.test.tsx │ │ └── index.tsx │ ├── 64051580 │ │ ├── route.js │ │ └── route.test.js │ ├── 64069204 │ │ ├── serverRequest.service.js │ │ └── serverRequest.service.spec.js │ ├── 64101015 │ │ ├── ProgramService.js │ │ ├── ProgramService.spec.js │ │ └── SubsciberProgram.js │ ├── 64148085 │ │ ├── Counter.test.tsx │ │ └── Counter.tsx │ ├── 64198516 │ │ ├── customhooks.js │ │ ├── index.js │ │ └── index.test.js │ ├── 64217332 │ │ ├── Category.js │ │ ├── Category.test.js │ │ └── validate.js │ ├── 64228834 │ │ ├── Dashboard.test.tsx │ │ ├── Dashboard.tsx │ │ └── useTitle.ts │ ├── 64240490 │ │ └── index.test.tsx │ ├── 64259504 │ │ ├── index.js │ │ └── index.test.js │ ├── 64271662 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 64311760 │ │ ├── ctrl.js │ │ └── ctrl.spec.js │ ├── 64327189 │ │ ├── command-option.js │ │ ├── command-option.test.js │ │ └── commands │ │ │ └── options │ │ │ └── host.js │ ├── 64344387 │ │ ├── functions.js │ │ └── functions.test.js │ ├── 64382021 │ │ ├── handler │ │ │ └── handler.js │ │ ├── main.js │ │ └── main.test.js │ ├── 64385009 │ │ ├── index.js │ │ └── index.spec.js │ ├── 64386858 │ │ ├── app.js │ │ └── app.spec.js │ ├── 64473533 │ │ ├── config.js │ │ ├── main.js │ │ └── main.test.js │ ├── 64477184 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 64485251 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 64549093 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 64564148 │ │ ├── setAuthToken.test.ts │ │ └── setAuthToken.ts │ ├── 64564233 │ │ ├── handler.js │ │ └── handler.test.js │ ├── 64575307 │ │ ├── send.js │ │ └── send.test.js │ ├── 64584113 │ │ └── index.ts │ ├── 64635170 │ │ ├── Map.js │ │ └── Map.test.js │ ├── 64648688 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 64768906 │ │ ├── app.js │ │ ├── www.js │ │ └── www.test.js │ ├── 64803187 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 64811936 │ │ ├── collection.ts │ │ ├── index.test.ts │ │ └── index.ts │ ├── 64817280 │ │ ├── Card.jsx │ │ ├── CardList.jsx │ │ └── CardList.test.jsx │ ├── 64818492 │ │ └── index.test.ts │ ├── 64857093 │ │ ├── get-secrets.test.ts │ │ └── get-secrets.ts │ ├── 64858662 │ │ ├── example.js │ │ └── example.test.js │ ├── 64975712 │ │ ├── foo.html │ │ └── foo.test.js │ ├── 64988386 │ │ ├── index.jsx │ │ └── index.test.jsx │ ├── 65042421 │ │ └── index.test.ts │ ├── 65049305 │ │ ├── app.test.ts │ │ ├── app.ts │ │ └── config.ts │ ├── 65068033 │ │ ├── calculateAverage.test.ts │ │ └── calculateAverage.ts │ ├── 65097473 │ │ ├── ValueClass.js │ │ ├── component.js │ │ └── component.test.js │ ├── 65112057 │ │ ├── deivce.ts │ │ └── device.test.ts │ ├── 65135435 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 65145829 │ │ ├── actions.js │ │ ├── reducer.js │ │ └── reducer.test.js │ ├── 65148503 │ │ ├── tsconfig.json │ │ └── user.ts │ ├── 65167311 │ │ ├── axiosInstance.js │ │ ├── config.js │ │ ├── index.jsx │ │ ├── index.test.jsx │ │ └── services.js │ ├── 65174562 │ │ └── index.test.ts │ ├── 65179710 │ │ ├── apiLambda.js │ │ ├── apiLambda.test.js │ │ └── testUtils.js │ ├── 65207598 │ │ └── helpers.js │ ├── 65220363 │ │ ├── index.test.ts │ │ └── index.ts │ ├── 45175599-todo │ │ ├── index.spec.ts │ │ └── index.ts │ ├── 46133847-todo │ │ ├── 01 │ │ │ ├── index.test.tsx │ │ │ └── index.tsx │ │ └── 02 │ │ │ ├── index.test.tsx │ │ │ └── index.tsx │ └── 64646680-todo │ │ ├── index.test.tsx │ │ └── index.tsx └── timer-mock │ ├── module.test.ts │ ├── module.ts │ └── module.v2.test.ts ├── tsconfig.json ├── tslint.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = false 9 | insert_final_newline = false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .env 4 | 5 | npm-debug.log 6 | npm-debug.log* 7 | yarn-error.log* 8 | 9 | .idea 10 | .DS_STORE 11 | .tmp -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all", 4 | "printWidth": 140, 5 | "arrowParens": "always" 6 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "10.16.0" 4 | install: 5 | - npm install 6 | jobs: 7 | include: 8 | - stage: "test" 9 | name: "unit tests with coverage" 10 | script: npm run coverall 11 | stages: 12 | - test 13 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | - [x] https://stackoverflow.com/questions/50085505/testing-typescript-code-with-namespaces-by-jest-ts-jest 4 | - [ ] https://stackoverflow.com/questions/45175599/mock-a-namespace-and-a-function-with-same-name-using-jest 5 | -------------------------------------------------------------------------------- /jest.setup.js: -------------------------------------------------------------------------------- 1 | import '@testing-library/jest-dom/extend-expect'; 2 | -------------------------------------------------------------------------------- /src/__mocks_disable__/axios.ts: -------------------------------------------------------------------------------- 1 | const axiosMocked = { 2 | get: jest.fn(), 3 | }; 4 | export default axiosMocked; 5 | -------------------------------------------------------------------------------- /src/async/User.ts: -------------------------------------------------------------------------------- 1 | class User { 2 | constructor(public name: string, public age: number) {} 3 | } 4 | 5 | export default User; 6 | -------------------------------------------------------------------------------- /src/automatic-mocks/utils.ts: -------------------------------------------------------------------------------- 1 | const utils = { 2 | getJSON: data => JSON.stringify(data), 3 | authorize: () => 'token', 4 | isAuthorized: secret => secret === 'wizard' 5 | }; 6 | 7 | export default utils; 8 | -------------------------------------------------------------------------------- /src/import-undefined-issue/01/@types/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function __export(m) { 3 | for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; 4 | } 5 | exports.__esModule = true; 6 | __export(require("./user")); 7 | console.log('load index.ts'); 8 | -------------------------------------------------------------------------------- /src/import-undefined-issue/01/@types/index.ts: -------------------------------------------------------------------------------- 1 | export * from './user'; 2 | console.log('load index.ts'); 3 | -------------------------------------------------------------------------------- /src/import-undefined-issue/01/@types/user.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | var UserRoles; 4 | (function (UserRoles) { 5 | UserRoles["ADMIN"] = "ADMIN"; 6 | UserRoles["GUEST"] = "GUEST"; 7 | })(UserRoles || (UserRoles = {})); 8 | exports.UserRoles = UserRoles; 9 | -------------------------------------------------------------------------------- /src/import-undefined-issue/01/@types/user.ts: -------------------------------------------------------------------------------- 1 | enum UserRoles { 2 | ADMIN = 'ADMIN', 3 | GUEST = 'GUEST' 4 | } 5 | 6 | export { UserRoles }; 7 | -------------------------------------------------------------------------------- /src/import-undefined-issue/01/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { UserRoles } from './@types'; 2 | 3 | describe('import undefined issue test suites', () => { 4 | it('should be ADMIN', () => { 5 | expect(UserRoles.ADMIN).toBe('ADMIN'); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/import-undefined-issue/02/@types/user.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | exports.maxRetry = 5; 4 | -------------------------------------------------------------------------------- /src/import-undefined-issue/02/@types/user.ts: -------------------------------------------------------------------------------- 1 | export const maxRetry = 5; 2 | 3 | export enum UserRoles { 4 | ADMIN = 'ADMIN', 5 | GUEST = 'GUEST' 6 | } 7 | -------------------------------------------------------------------------------- /src/import-undefined-issue/02/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { UserRoles } from './@types/user'; 2 | 3 | describe.skip('import undefined issue - 2 test suites', () => { 4 | it('should be ADMIN', () => { 5 | expect(UserRoles.ADMIN).toBe('ADMIN'); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/jest-object/apple.ts: -------------------------------------------------------------------------------- 1 | module.exports = () => 'apple'; 2 | -------------------------------------------------------------------------------- /src/jest-object/banana.ts: -------------------------------------------------------------------------------- 1 | module.exports = () => 'banana'; 2 | -------------------------------------------------------------------------------- /src/jest-object/grape.ts: -------------------------------------------------------------------------------- 1 | module.exports = () => 'grape'; 2 | -------------------------------------------------------------------------------- /src/make-stub-for-generator/index.js: -------------------------------------------------------------------------------- 1 | function* func1() { 2 | yield 42; 3 | } 4 | 5 | function* func2() { 6 | yield* exports.func1(); 7 | } 8 | 9 | exports.func2 = func2; 10 | exports.func1 = func1; 11 | -------------------------------------------------------------------------------- /src/mock-and-destructuring/aws-sdk.ts: -------------------------------------------------------------------------------- 1 | export class SharedIniFileCredentials {} 2 | 3 | // tslint:disable-next-line: max-classes-per-file 4 | export class SecretsManager {} 5 | -------------------------------------------------------------------------------- /src/mock-and-destructuring/main.ts: -------------------------------------------------------------------------------- 1 | import { SecretsManager, SharedIniFileCredentials } from "./aws-sdk"; 2 | 3 | export function main() { 4 | const credentials = new SharedIniFileCredentials(); 5 | const secretsManager = new SecretsManager(); 6 | } 7 | -------------------------------------------------------------------------------- /src/mock-es6-class/Component.ts: -------------------------------------------------------------------------------- 1 | class Component { 2 | get isBottom(): boolean { 3 | return true; 4 | } 5 | 6 | public render(): any { 7 | return this.isBottom; 8 | } 9 | } 10 | 11 | export default Component; 12 | -------------------------------------------------------------------------------- /src/mock-es6-class/db.ts: -------------------------------------------------------------------------------- 1 | import faker from 'faker'; 2 | 3 | const DB = { 4 | locations: [{ id: 1, name: faker.address.city() }, { id: 2, name: faker.address.city() }] 5 | }; 6 | 7 | export { DB }; 8 | -------------------------------------------------------------------------------- /src/mock-es6-class/mock-class-getter/index.spec.ts: -------------------------------------------------------------------------------- 1 | import Component from '../Component'; 2 | const comp = new Component(); 3 | 4 | Object.defineProperty(comp, 'isBottom', { 5 | get: jest.fn((): boolean => false) 6 | }); 7 | 8 | describe('component test suites', () => { 9 | it('t-1', () => { 10 | expect(comp.isBottom).toBeFalsy(); 11 | }); 12 | 13 | it('t-2', () => { 14 | expect(comp.render()).toBeFalsy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/mock-function/callback/toBeTested.ts: -------------------------------------------------------------------------------- 1 | function toBeTested(id, values, xyz, callback) { 2 | return xyz(id, values, callback); 3 | } 4 | 5 | export { toBeTested }; 6 | -------------------------------------------------------------------------------- /src/mock-function/callback/xyz.ts: -------------------------------------------------------------------------------- 1 | function xyz(id, values, callback) { 2 | return callback(); 3 | } 4 | 5 | export default xyz; 6 | -------------------------------------------------------------------------------- /src/mock-function/cmd-export-class/module.ts: -------------------------------------------------------------------------------- 1 | class MyService { 2 | public getMessage(): string { 3 | return `Her name is ${this.genName()}, age is ${this.getAge()}`; 4 | } 5 | 6 | public genName(): string { 7 | return 'novaline'; 8 | } 9 | 10 | public getAge(): number { 11 | return 26; 12 | } 13 | } 14 | 15 | module.exports = MyService; 16 | -------------------------------------------------------------------------------- /src/mock-function/cmd/module.js: -------------------------------------------------------------------------------- 1 | exports.getMessage = function(num) { 2 | return `Her name is ${exports.genName(num)}, age is ${exports.getAge()}`; 3 | }; 4 | 5 | exports.genName = (num) => 'novaline'; 6 | 7 | exports.getAge = () => 26; 8 | -------------------------------------------------------------------------------- /src/mock-function/es6-module-1/module.ts: -------------------------------------------------------------------------------- 1 | const genName = (): string => 'novaline'; 2 | const getAge = (): number => 26; 3 | 4 | function getMessage(): string { 5 | return `Her name is ${genName()}, age is ${getAge()}`; 6 | } 7 | 8 | export default { 9 | getMessage, 10 | genName, 11 | getAge 12 | }; 13 | -------------------------------------------------------------------------------- /src/mock-function/es6-module-2/module.ts: -------------------------------------------------------------------------------- 1 | export function getMessage(num: number): string { 2 | return `Her name is ${genName(num)}`; 3 | } 4 | 5 | export function genName(num: number): string { 6 | return 'novaline'; 7 | } 8 | -------------------------------------------------------------------------------- /src/mock-function/es6-module-3/module.test.ts: -------------------------------------------------------------------------------- 1 | import * as m from './module'; 2 | 3 | describe('mock function test suites', () => { 4 | // 在一个文件中使用export导出多个函数,mock m.genName函数失败 5 | it('t-1', () => { 6 | // m.genName = jest.fn(() => 'emilie'); 7 | // expect(jest.isMockFunction(m.genName)).toBeTruthy(); 8 | // expect(m.genName()).toBe('emilie'); 9 | // expect(m.getMessage()).toEqual('Her name is emilie, age is 26'); 10 | // expect(m.genName).toHaveBeenCalled(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/mock-function/es6-module-3/module.ts: -------------------------------------------------------------------------------- 1 | export function getMessage(num?: number): string { 2 | return `Her name is ${genName(num)}, age is ${getAge()}`; 3 | } 4 | 5 | export function genName(num?: number): string { 6 | return 'novaline'; 7 | } 8 | 9 | export function getAge(): number { 10 | return 26; 11 | } 12 | -------------------------------------------------------------------------------- /src/mock-function/es6-module-4/module.ts: -------------------------------------------------------------------------------- 1 | class MyService { 2 | public getMessage(): string { 3 | return `Her name is ${this.genName()}, age is ${this.getAge()}`; 4 | } 5 | 6 | public genName(): string { 7 | return 'novaline'; 8 | } 9 | 10 | public getAge(): number { 11 | return 26; 12 | } 13 | } 14 | export default MyService; 15 | -------------------------------------------------------------------------------- /src/mock-function/es6-module-5/interfaces.ts: -------------------------------------------------------------------------------- 1 | export interface IObj { 2 | getMessage: () => string; 3 | genName: () => string; 4 | getAge: () => number; 5 | } 6 | -------------------------------------------------------------------------------- /src/mock-function/es6-module-5/module.ts: -------------------------------------------------------------------------------- 1 | import { IObj } from './interfaces'; 2 | 3 | const obj: IObj = { 4 | getMessage() { 5 | return `Her name is ${this.genName()}, age is ${this.getAge()}`; 6 | }, 7 | 8 | genName() { 9 | return 'novaline'; 10 | }, 11 | 12 | getAge() { 13 | return 26; 14 | } 15 | }; 16 | 17 | export default obj; 18 | -------------------------------------------------------------------------------- /src/mock-http-request/interfaces/user.ts: -------------------------------------------------------------------------------- 1 | import User from '../user.model'; 2 | 3 | export interface IUserMap { 4 | [index: number]: User; 5 | } 6 | 7 | export interface IUser { 8 | name: string; 9 | } 10 | -------------------------------------------------------------------------------- /src/mock-http-request/myRequest.ts: -------------------------------------------------------------------------------- 1 | import http from 'http'; 2 | 3 | function myRequest(url: string): Promise { 4 | return new Promise((resolve) => { 5 | http.get({ path: url }, (response: http.IncomingMessage): void => { 6 | let result: any; 7 | response.on('data', (data: any) => (result += data)); 8 | response.on('end', () => resolve(result)); 9 | }); 10 | }); 11 | } 12 | 13 | export default myRequest; 14 | -------------------------------------------------------------------------------- /src/mock-http-request/user.model.ts: -------------------------------------------------------------------------------- 1 | import { IUser } from './interfaces/user'; 2 | 3 | class User { 4 | private name: string = ''; 5 | constructor(user?: IUser) { 6 | if (user) { 7 | this.name = user.name; 8 | } 9 | } 10 | 11 | public getName(): string { 12 | return this.name; 13 | } 14 | } 15 | 16 | export default User; 17 | -------------------------------------------------------------------------------- /src/mock-module/axios/index.ts: -------------------------------------------------------------------------------- 1 | export const actions = { 2 | $axios: { 3 | $get: url => '' 4 | }, 5 | async submitPhoneNumber(context) { 6 | let data = await this.$axios.$get('https://jsonplaceholder.typicode.com/todos/1'); 7 | // do something with data 8 | 9 | data = this.processData(data); 10 | return data; 11 | }, 12 | 13 | processData(data) { 14 | return data; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /src/mock-module/demo-1/LocationService.ts: -------------------------------------------------------------------------------- 1 | import LocationDAOImpl, { ILocationDAO } from './LocationDAOImpl'; 2 | 3 | class LocationService { 4 | private locationDAOImpl: ILocationDAO; 5 | constructor() { 6 | this.locationDAOImpl = new LocationDAOImpl(); 7 | } 8 | 9 | public async findById(id: number) { 10 | return this.locationDAOImpl.findById(id); 11 | } 12 | } 13 | 14 | export { LocationService }; 15 | -------------------------------------------------------------------------------- /src/mock-module/demo-1/db.ts: -------------------------------------------------------------------------------- 1 | import faker from 'faker'; 2 | 3 | const DB = { 4 | locations: [{ id: 1, name: faker.address.city() }, { id: 2, name: faker.address.city() }] 5 | }; 6 | 7 | export { DB }; 8 | -------------------------------------------------------------------------------- /src/mock-module/node-fetch/index.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch'; 2 | 3 | function fetchBlobImage() { 4 | const url = ''; 5 | return fetch(url) 6 | .then(response => response.blob) 7 | .then(blob => processImage(blob)); 8 | } 9 | 10 | function processImage(blob) { 11 | return JSON.stringify(blob); 12 | } 13 | 14 | export { fetchBlobImage }; 15 | -------------------------------------------------------------------------------- /src/mock-ts-namespace/index.ts: -------------------------------------------------------------------------------- 1 | import firebase from 'firebase'; 2 | 3 | export function signInWithgoogle() { 4 | const provider = new firebase.auth.GoogleAuthProvider(); 5 | firebase.auth().signInWithRedirect(provider); 6 | } 7 | -------------------------------------------------------------------------------- /src/multiple-beforeAll/a.spec.ts: -------------------------------------------------------------------------------- 1 | import { envVars, IEnvVars } from './envVars'; 2 | 3 | let env: IEnvVars; 4 | beforeAll(async () => { 5 | env = await envVars; 6 | console.log('a - beforeAll env:', env); 7 | }); 8 | 9 | describe('a test suites', () => { 10 | console.log('a - describe scope env:', env); 11 | it('Test', () => { 12 | console.log('a - test case scope env:', env); 13 | expect(1).toBe(1); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/multiple-beforeAll/b.spec.ts: -------------------------------------------------------------------------------- 1 | import { envVars, IEnvVars } from './envVars'; 2 | 3 | let env: IEnvVars; 4 | beforeAll(async () => { 5 | env = await envVars; 6 | console.log('b - beforeAll env:', env); 7 | }); 8 | 9 | describe('b test suites', () => { 10 | console.log('b - env:', env); 11 | it('Test', () => { 12 | expect(1).toBe(1); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/multiple-beforeAll/c.spec.ts: -------------------------------------------------------------------------------- 1 | import { getEnvVars, IEnvVars } from './envVars'; 2 | 3 | let env: IEnvVars; 4 | beforeAll(async () => { 5 | env = await getEnvVars(); 6 | console.log('c - beforeAll env:', env); 7 | }); 8 | 9 | describe('c test suites', () => { 10 | console.log('c - env:', env); 11 | it('Test', () => { 12 | expect(1).toBe(1); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/open-handle-potentially-keeping-Jest-from-exiting/UserService.ts: -------------------------------------------------------------------------------- 1 | import { PubSub } from './pubsub'; 2 | 3 | class UserService { 4 | public static findById() { 5 | return 'slideshowp2'; 6 | } 7 | 8 | public static create() { 9 | PubSub.publish('new user'); 10 | } 11 | } 12 | 13 | export { UserService }; 14 | -------------------------------------------------------------------------------- /src/open-handle-potentially-keeping-Jest-from-exiting/__tests__/UserService.spec.ts: -------------------------------------------------------------------------------- 1 | jest.useFakeTimers(); 2 | import { UserService } from '../UserService'; 3 | 4 | describe('UserService', () => { 5 | it('should find user by id correctly', () => { 6 | const actualValue = UserService.findById(); 7 | expect(actualValue).toBe('slideshowp2'); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /src/open-handle-potentially-keeping-Jest-from-exiting/pubsub.ts: -------------------------------------------------------------------------------- 1 | const noopTimer = setTimeout(() => {}, 0); 2 | 3 | class PubSub { 4 | public static publish(message) { 5 | console.log(message); 6 | } 7 | } 8 | 9 | export { PubSub }; 10 | -------------------------------------------------------------------------------- /src/react-enzyme-examples/01-quick-start/Foo.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | class Foo extends React.Component { 4 | constructor(props) { 5 | super(props); 6 | } 7 | 8 | public render() { 9 | return
Bar
; 10 | } 11 | } 12 | 13 | export default Foo; 14 | -------------------------------------------------------------------------------- /src/react-enzyme-examples/02-react-hooks/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const SampleComponent = () => { 4 | const sampleMethod = () => { 5 | console.log('hello world'); 6 | }; 7 | 8 | return ( 9 | 12 | ); 13 | }; 14 | 15 | export default SampleComponent; 16 | -------------------------------------------------------------------------------- /src/react-test-renderer-examples/02-react-sfc/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const SampleComponent = () => { 4 | const sampleMethod = () => { 5 | console.log('hello world'); 6 | }; 7 | 8 | return ( 9 | 12 | ); 13 | }; 14 | 15 | export default SampleComponent; 16 | -------------------------------------------------------------------------------- /src/stackoverflow/36082197/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import $ from 'jquery'; 3 | 4 | class SomeComponent extends Component { 5 | componentDidMount() { 6 | $(window).on('resize', this.resizeEventHandler); 7 | } 8 | 9 | resizeEventHandler() { 10 | console.log('resize event handler'); 11 | } 12 | 13 | render() { 14 | return
some component
; 15 | } 16 | } 17 | 18 | export default SomeComponent; 19 | -------------------------------------------------------------------------------- /src/stackoverflow/38129774/ajax.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | export const status = ({ loginUrl = '/', logoutUrl = '/' }) => { 4 | return axios.get(`/auth?login=${loginUrl}&logout=${logoutUrl}`); 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/42137891/auth0/WebAuth.ts: -------------------------------------------------------------------------------- 1 | export class WebAuth { 2 | public client = { 3 | login(options, callback) { 4 | callback(null, {}); 5 | } 6 | }; 7 | constructor(...args: any) {} 8 | } 9 | -------------------------------------------------------------------------------- /src/stackoverflow/42137891/auth0/index.ts: -------------------------------------------------------------------------------- 1 | export * from './WebAuth'; 2 | -------------------------------------------------------------------------------- /src/stackoverflow/42676657/article-api.js: -------------------------------------------------------------------------------- 1 | const fetch = require('node-fetch'); 2 | 3 | function articleMiddleware(next) { 4 | const articleApiListUrl = 'https://github.com/mrdulin'; 5 | const headers = {}; 6 | const method = 'get'; 7 | const body = {}; 8 | 9 | return fetch(articleApiListUrl, { headers, method, body }).then(() => next({ some: 'data' })); 10 | } 11 | 12 | exports.articleMiddleware = articleMiddleware; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/43292263/main.spec.ts: -------------------------------------------------------------------------------- 1 | import * as someModule from './sharedMocks'; 2 | import { main } from './main'; 3 | 4 | jest.mock('./someModule.ts', () => someModule); 5 | 6 | describe('test suites A', () => { 7 | it('t1', () => { 8 | someModule.findById.mockReturnValueOnce('mocked data'); 9 | const actualValue = main(); 10 | expect(actualValue).toBe('mocked data'); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/43292263/main.ts: -------------------------------------------------------------------------------- 1 | import { findById } from './someModule'; 2 | 3 | function main() { 4 | return findById(); 5 | } 6 | 7 | export { main }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/43292263/other.spec.ts: -------------------------------------------------------------------------------- 1 | import { other } from './other'; 2 | 3 | describe('other', () => { 4 | it('t1', () => { 5 | const actualValue = other(); 6 | expect(actualValue).toBe('real data by name'); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /src/stackoverflow/43292263/other.ts: -------------------------------------------------------------------------------- 1 | import { findByName } from './someModule'; 2 | 3 | function other() { 4 | return findByName(); 5 | } 6 | 7 | export { other }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/43292263/sharedMocks.ts: -------------------------------------------------------------------------------- 1 | const findById = jest.fn(); 2 | 3 | export { findById }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/43292263/someModule.ts: -------------------------------------------------------------------------------- 1 | function findById() { 2 | return 'real data by id'; 3 | } 4 | 5 | function findByName() { 6 | return 'real data by name'; 7 | } 8 | 9 | export { findById, findByName }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/45175599-todo/index.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable-next-line: no-namespace 2 | export namespace Foo { 3 | export function bar() { 4 | console.log('bar'); 5 | } 6 | 7 | export namespace Bar { 8 | export function baz() { 9 | exports.bar(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/45702292/chai.setup.js: -------------------------------------------------------------------------------- 1 | global.chai = require('chai') -------------------------------------------------------------------------------- /src/stackoverflow/45702292/index.test.js: -------------------------------------------------------------------------------- 1 | describe('45702292', () => { 2 | it.skip('should pass', () => { 3 | chai.expect(1+1).to.be.eq(2) 4 | }); 5 | }); 6 | -------------------------------------------------------------------------------- /src/stackoverflow/45918386/index.ts: -------------------------------------------------------------------------------- 1 | export const toggleClass = (elementDOM, className) => { 2 | if (elementDOM.classList.contains(className)) { 3 | elementDOM.classList.remove(className); 4 | } else { 5 | elementDOM.classList.add(className); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/46133847-todo/01/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const LocationFinderSearch = ({ onLocationChange, onSearchClick, inputValue }) => ( 4 |
5 | 6 | 7 |
8 | ); 9 | 10 | export default LocationFinderSearch; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/46133847-todo/02/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const Comp = ({ onChange }) => ( 4 |
5 | onChange(e)} /> 6 |
7 | ); 8 | 9 | export default Comp; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/46152048/someAsyncFunction.js: -------------------------------------------------------------------------------- 1 | export async function someAsyncFunction() {} 2 | -------------------------------------------------------------------------------- /src/stackoverflow/46213271/index.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class Link extends Component { 4 | onClick(e, tf) { 5 | e.stopPropagation(); 6 | if (tf) { 7 | e.preventDefault(); 8 | } 9 | } 10 | render() { 11 | const { tf } = this.props; 12 | return ( 13 | this.onClick(e, tf)}> 14 | my link 15 | 16 | ); 17 | } 18 | } 19 | 20 | export default Link; 21 | -------------------------------------------------------------------------------- /src/stackoverflow/46431638/globals.ts: -------------------------------------------------------------------------------- 1 | export const document = { 2 | getElementsByTagName() { 3 | return 'real element'; 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/46431638/index.test.ts: -------------------------------------------------------------------------------- 1 | import { Overlay } from './'; 2 | 3 | jest.mock('./globals', () => ({ 4 | document: { 5 | getElementsByTagName: jest.fn().mockReturnValue('foo'), 6 | }, 7 | })); 8 | 9 | describe('46431638', () => { 10 | it('should mock and pass', () => { 11 | jest.spyOn(console, 'log'); 12 | Overlay(); 13 | expect(console.log).toBeCalledWith('foo'); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/stackoverflow/46431638/index.ts: -------------------------------------------------------------------------------- 1 | import { document } from './globals'; 2 | 3 | export const Overlay = () => { 4 | console.log(document.getElementsByTagName()); 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/46437290/utils.js: -------------------------------------------------------------------------------- 1 | const buildEngine = () => 'Engine'; 2 | 3 | const buildCar = () => { 4 | const engine = exports.buildEngine(); 5 | return engine + ' and ' + 'Car Body'; 6 | }; 7 | 8 | exports.buildEngine = buildEngine; 9 | exports.buildCar = buildCar; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/46911799/index.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | 3 | function readdirSync(path) { 4 | return fs.readdirSync(path); 5 | } 6 | 7 | export { readdirSync }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/47093028/MyAnotherClass.ts: -------------------------------------------------------------------------------- 1 | export class B { 2 | someBFunctionFoo(arg) { 3 | console.log('real someBFunctionFoo implementation'); 4 | } 5 | someBFunctionBar() { 6 | console.log('real someBFunctionBar implementation'); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/stackoverflow/47093028/MyClass.ts: -------------------------------------------------------------------------------- 1 | import { B } from './MyAnotherClass'; 2 | 3 | export class A { 4 | f2() { 5 | const instance = new B(); 6 | instance.someBFunctionFoo('arg'); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/stackoverflow/47412169/Translate.ts: -------------------------------------------------------------------------------- 1 | const Translator = { 2 | trans: text => text 3 | }; 4 | 5 | (global as any).Translator = Translator; 6 | 7 | export { Translator }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/47412169/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './Translate'; 3 | 4 | interface ISomeComponentProps { 5 | title: string; 6 | } 7 | 8 | class SomeComponent extends React.Component { 9 | public render() { 10 | const title = (global as any).Translator.trans(this.props.title); 11 | return
title: {title}
; 12 | } 13 | } 14 | 15 | export { SomeComponent }; 16 | -------------------------------------------------------------------------------- /src/stackoverflow/47531051/__mocks__/api.ts: -------------------------------------------------------------------------------- 1 | const users = ['Jhon', 'Paul', 'Ringo']; 2 | 3 | export default function getUsers() { 4 | return new Promise((resolve, reject) => { 5 | process.nextTick(() => { 6 | resolve(users); 7 | }); 8 | }); 9 | } 10 | -------------------------------------------------------------------------------- /src/stackoverflow/47531051/api.test.ts: -------------------------------------------------------------------------------- 1 | import getUsers from './api'; 2 | 3 | jest.mock('./api'); 4 | 5 | test('user list is an array', async () => { 6 | expect.assertions(1); 7 | const resp = await getUsers(); 8 | expect(Array.isArray(resp)).toBeTruthy(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/stackoverflow/47531051/api.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch'; 2 | 3 | export default async function getUsers() { 4 | const resp = await fetch(`/users`); 5 | const data = await resp.json(); 6 | return data.message; 7 | } 8 | -------------------------------------------------------------------------------- /src/stackoverflow/47540126/moduleA.ts: -------------------------------------------------------------------------------- 1 | export const hash = async (data: string) => { 2 | return 'real hashed value'; 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/47560126/showErrorAlert.ts: -------------------------------------------------------------------------------- 1 | export function showErrorAlert(jsonResponse) { 2 | console.log(jsonResponse); 3 | } 4 | -------------------------------------------------------------------------------- /src/stackoverflow/47587358/user.js: -------------------------------------------------------------------------------- 1 | export class User { 2 | constructor(nick, firstName, userName, phoneNumber, userId) { 3 | this.nick = nick; 4 | this.firstName = firstName; 5 | this.userName = userName; 6 | this.phoneNumber = phoneNumber; 7 | this.userId = userId; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/stackoverflow/47587358/userTable.js: -------------------------------------------------------------------------------- 1 | const userTable = { 2 | find() { 3 | return this; 4 | }, 5 | sort() { 6 | return this; 7 | }, 8 | exec(fn) { 9 | console.log('real exec'); 10 | fn(); 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/47704309/actions.js: -------------------------------------------------------------------------------- 1 | export const CANCEL_EDITS = 'CANCEL_EDITS'; 2 | 3 | export const cancelEdits = () => ({ 4 | type: CANCEL_EDITS, 5 | }); 6 | -------------------------------------------------------------------------------- /src/stackoverflow/47704309/reducer.js: -------------------------------------------------------------------------------- 1 | import * as Actions from './actions'; 2 | 3 | export function commonReducer(state, action) { 4 | switch (action.type) { 5 | case Actions.CANCEL_EDITS: 6 | return window.location.reload(); 7 | default: 8 | return state; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/stackoverflow/47865190/app.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | 4 | app.post('/auth/signup', (req, res) => { 5 | const data = { 6 | success: true, 7 | message: 'registration success', 8 | token: '123', 9 | user: {}, 10 | }; 11 | res.json(data); 12 | }); 13 | 14 | module.exports = app; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/47921226/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | export default class ToggleCheckbox extends Component { 4 | constructor(props) { 5 | super(props); 6 | this.onChange = this.onChange.bind(this); 7 | } 8 | 9 | public onChange() { 10 | console.log('onChange'); 11 | } 12 | public render() { 13 | return ( 14 |
15 | {' '} 16 |
17 | ); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/stackoverflow/47953161/index.ts: -------------------------------------------------------------------------------- 1 | export async function main(User) { 2 | const trx = 'the trx'; 3 | const userData = {}; 4 | let user = await User.query(trx).insert(userData); 5 | return user.toJSON(); 6 | } 7 | -------------------------------------------------------------------------------- /src/stackoverflow/48006588/buildUrl.js: -------------------------------------------------------------------------------- 1 | import config from './config'; 2 | 3 | export function buildUrl(contentId, data, options = {}) { 4 | let baseUrl = config.has('imgBaseUrl') && config.get('imgBaseUrl'); 5 | if (!baseUrl) { 6 | throw new Error('some error'); 7 | } 8 | console.log(baseUrl); 9 | } 10 | -------------------------------------------------------------------------------- /src/stackoverflow/48006588/config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | config: {}, 3 | has(key) { 4 | return !!config[key]; 5 | }, 6 | get(key) { 7 | return config[key]; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/48146038/action.ts: -------------------------------------------------------------------------------- 1 | import { createBrowserHistory } from 'history'; 2 | 3 | const history = createBrowserHistory(); 4 | 5 | export function someAction() { 6 | history.push('/home'); 7 | 8 | return { 9 | type: 'NAVIGATE_HOME', 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /src/stackoverflow/50085505/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { MainNamespace } from './'; 2 | 3 | describe('MainNamespace', () => { 4 | it('sum test', () => { 5 | const mainClass = new MainNamespace.MainClass(); 6 | expect(mainClass.sum(3, 2)).toEqual(5); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /src/stackoverflow/50085505/index.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable-next-line: no-namespace 2 | export namespace MainNamespace { 3 | export class MainClass { 4 | public sum(a: number, b: number): number { 5 | return a + b; 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/stackoverflow/50217960/Foo.ts: -------------------------------------------------------------------------------- 1 | interface IFoo { 2 | myFunc(): string; 3 | otherFunc(): number; 4 | } 5 | 6 | class Foo implements IFoo { 7 | public myFunc(): string { 8 | return 'myFunc'; 9 | } 10 | public otherFunc(): number { 11 | return 1; 12 | } 13 | } 14 | 15 | export { Foo, IFoo }; 16 | -------------------------------------------------------------------------------- /src/stackoverflow/50217960/SomeClass.ts: -------------------------------------------------------------------------------- 1 | import { IFoo } from './Foo'; 2 | 3 | interface ISomeClass { 4 | say(): string; 5 | } 6 | 7 | interface ISomeClassOptions { 8 | foo: IFoo; 9 | } 10 | 11 | class SomeClass implements ISomeClass { 12 | private foo: IFoo; 13 | constructor(options: ISomeClassOptions) { 14 | this.foo = options.foo; 15 | } 16 | public say(): string { 17 | return this.foo.myFunc(); 18 | } 19 | } 20 | 21 | export { SomeClass, ISomeClassOptions }; 22 | -------------------------------------------------------------------------------- /src/stackoverflow/50540892/foo.test.tsx: -------------------------------------------------------------------------------- 1 | import { Foo } from './foo'; 2 | import React from 'react'; 3 | import { shallow } from 'enzyme'; 4 | 5 | describe('check foo Component', () => { 6 | it('data is false', () => { 7 | const wrapper = shallow(); 8 | expect(wrapper.contains('Hi')).toBeTruthy(); 9 | }); 10 | it('data is true', () => { 11 | const wrapper = shallow(); 12 | expect(wrapper.contains('Hello')).toBeTruthy(); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/stackoverflow/50540892/foo.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | function Foo({ data }) { 4 | if (data === true) { 5 | return ( 6 |
7 | Hello 8 |
9 | ); 10 | } else { 11 | return ( 12 |
13 | Hi 14 |
15 | ); 16 | } 17 | } 18 | 19 | export { Foo }; 20 | -------------------------------------------------------------------------------- /src/stackoverflow/50912106/index.ts: -------------------------------------------------------------------------------- 1 | export class MyClass { 2 | constructor() {} 3 | 4 | public async func1() { 5 | return this.func2(); 6 | } 7 | public func2(int?: number) { 8 | return false; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/stackoverflow/51275648/Apple.js: -------------------------------------------------------------------------------- 1 | function Apple() { 2 | return Orange(1, 2); 3 | } 4 | 5 | function Orange(arg1, arg2) { 6 | return arg1 + arg2; 7 | } 8 | 9 | exports.Apple = Apple; 10 | exports.Orange = exports.Orange; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/51275648/Apple.spec.js: -------------------------------------------------------------------------------- 1 | const functions = require('./Apple.js'); 2 | 3 | describe('Apple', () => { 4 | it('Should run Apple', () => { 5 | functions.Orange = jest.fn().mockImplementation(() => { 6 | return 3; 7 | }); 8 | expect(functions.Apple()).toEqual(3); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/stackoverflow/51566816/index.ts: -------------------------------------------------------------------------------- 1 | export function getUserInfo() { 2 | const userInfo = window.sessionStorage.getItem('userInfo'); 3 | if (userInfo) { 4 | return JSON.parse(userInfo); 5 | } 6 | return {}; 7 | } 8 | -------------------------------------------------------------------------------- /src/stackoverflow/51983850/actionTypes.ts: -------------------------------------------------------------------------------- 1 | export const FETCH_ORDERS_START = 'FETCH_ORDERS_START'; 2 | export const FETCH_ORDERS_SUCCESS = 'FETCH_ORDERS_SUCCESS'; 3 | export const FETCH_ORDERS_FAILED = 'FETCH_ORDERS_FAILED'; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/52025257/actionCreators.ts: -------------------------------------------------------------------------------- 1 | import followApi from './followApi'; 2 | 3 | export const handleFavorite = data => { 4 | return dispatch => { 5 | return followApi.handleFavorite(data).then( 6 | payload => { 7 | dispatch({ type: 'HANDLE_FAVORITE_SUCCESS', payload }); 8 | }, 9 | err => { 10 | dispatch({ type: 'ERROR', payload: err }); 11 | } 12 | ); 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/52075711/A.spec.ts: -------------------------------------------------------------------------------- 1 | import A from './A'; 2 | import { Y } from './util'; 3 | 4 | jest.mock('./util.ts', () => { 5 | return { 6 | Y: jest.fn() 7 | }; 8 | }); 9 | 10 | const a = new A(); 11 | 12 | describe('A', () => { 13 | it('should execute function Y correctly', () => { 14 | const mockedReq = {}; 15 | const mockedRes = {}; 16 | a.X(mockedReq, mockedRes); 17 | expect(Y).toBeCalledTimes(1); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /src/stackoverflow/52075711/A.ts: -------------------------------------------------------------------------------- 1 | import B from './B'; 2 | import { Y } from './util'; 3 | 4 | export default class A extends B { 5 | constructor() { 6 | super('/A'); 7 | this.setCors(''); 8 | this.app.post('', this.X.bind(this)); 9 | } 10 | 11 | public X(req, res) { 12 | Y(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/stackoverflow/52075711/B.ts: -------------------------------------------------------------------------------- 1 | export default class B { 2 | public app = { 3 | post(route: string, controller: () => any) { 4 | // 5 | } 6 | }; 7 | private name: string = ''; 8 | private url: string = ''; 9 | constructor(name: string) { 10 | this.name = name; 11 | } 12 | 13 | protected setCors(url: string) { 14 | this.url = url; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/stackoverflow/52075711/util.ts: -------------------------------------------------------------------------------- 1 | export function Y() { 2 | console.log('I am Y'); 3 | } 4 | -------------------------------------------------------------------------------- /src/stackoverflow/52172531/react-native-touch-id.ts: -------------------------------------------------------------------------------- 1 | const touchId = { 2 | isSupported() { 3 | return false; 4 | }, 5 | authenticate() { 6 | return false; 7 | } 8 | }; 9 | export default touchId; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/52326039/year-groups-selectors.ts: -------------------------------------------------------------------------------- 1 | const yearGroupsSelectors = { 2 | selectAllTeachers(state) { 3 | return 'real computed data based on state'; 4 | } 5 | }; 6 | 7 | export default yearGroupsSelectors; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/52550469/firebase.ts: -------------------------------------------------------------------------------- 1 | const firebase = { 2 | auth() { 3 | return firebase; 4 | }, 5 | async signInWithEmailAndPassword(email: string, password: string): Promise { 6 | return firebase; 7 | } 8 | }; 9 | 10 | export default firebase; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/52673113/__mocks__/checkNetwork.ts: -------------------------------------------------------------------------------- 1 | const checkNetwork = () => new Promise(resolve => resolve(true)); 2 | 3 | export default checkNetwork; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/52673113/checkNetwork.ts: -------------------------------------------------------------------------------- 1 | import NetInfo from '@react-native-community/netinfo'; 2 | import { NO_NETWORK_CONNECTION } from './errors'; 3 | 4 | const checkNetwork = (): Promise => 5 | new Promise((resolve, reject) => { 6 | NetInfo.isConnected 7 | .fetch() 8 | .then(isConnected => (isConnected ? resolve(true) : reject(NO_NETWORK_CONNECTION))) 9 | .catch(() => reject(NO_NETWORK_CONNECTION)); 10 | }); 11 | 12 | export default checkNetwork; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/52673113/errors.ts: -------------------------------------------------------------------------------- 1 | export const NO_NETWORK_CONNECTION = 'NO_NETWORK_CONNECTION'; 2 | -------------------------------------------------------------------------------- /src/stackoverflow/52729002/index.ts: -------------------------------------------------------------------------------- 1 | import * as models from './models'; 2 | import { MongoDb, Models } from './interfaces'; 3 | 4 | export class UserDataSource { 5 | private models: Models | null = null; 6 | public initialize(mongodb: MongoDb): this { 7 | if (!this.models) { 8 | this.models = { 9 | users: new models.UserModel(mongodb) 10 | }; 11 | } 12 | return this; 13 | } 14 | 15 | public getModels(): Models | null { 16 | return this.models || null; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/stackoverflow/52729002/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export interface MongoDb {} 2 | 3 | export interface Models {} 4 | -------------------------------------------------------------------------------- /src/stackoverflow/52729002/models/UserModel.ts: -------------------------------------------------------------------------------- 1 | import { MongoDb } from '../interfaces'; 2 | 3 | export class UserModel { 4 | constructor(private mongodb: MongoDb) {} 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/52729002/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from './UserModel'; 2 | -------------------------------------------------------------------------------- /src/stackoverflow/52831401/index.js: -------------------------------------------------------------------------------- 1 | import { Pool } from 'pg'; 2 | const pool = new Pool(); 3 | 4 | module.exports = { 5 | query: (text, params, callback) => { 6 | const start = Date.now(); 7 | 8 | return pool.query(text, params, (err, res) => { 9 | const duration = Date.now() - start; 10 | console.log('executed query', { text, duration, rows: res.rowCount }); 11 | callback(err, res); 12 | }); 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/52845000/anotherFunction.js: -------------------------------------------------------------------------------- 1 | module.exports = (app, io) => { 2 | return 'do something'; 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/52845000/myFunction.js: -------------------------------------------------------------------------------- 1 | const anotherFunction = require('./anotherFunction.js'); 2 | 3 | module.exports = (app, io) => { 4 | return (req, res) => { 5 | const { id, value } = req.query; 6 | req.app.locals['target' + id].pwmWrite(value); 7 | anotherFunction(app, io); 8 | res.send({ value }); 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/52887470/Button.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | export interface IButtonOwnProps { 4 | text: string; 5 | onClick(): void; 6 | } 7 | 8 | export class Button extends Component { 9 | public static defaultProps: IButtonOwnProps = { 10 | text: '', 11 | onClick: () => {} 12 | }; 13 | public render() { 14 | return ; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/stackoverflow/52899150/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`SomeComponent snapshot 1`] = ` 4 |
5 | test 6 |
7 | `; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/52944804/Button.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export const Button = props => { 4 | return ; 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/52944804/Input.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export const Input = ({ onChange, placeholder, name, value }) => { 4 | return ; 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/53788454/CustomComponent.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | interface ICustomComponentOwnProps { 4 | movies: any[]; 5 | } 6 | 7 | class CustomComponent extends React.Component { 8 | public render() { 9 | return
custom component
; 10 | } 11 | } 12 | 13 | export { CustomComponent }; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/53889291/functions.js: -------------------------------------------------------------------------------- 1 | function funcOne() { 2 | return exports.funcTwo(); 3 | } 4 | 5 | function funcTwo() { 6 | return 'func two'; 7 | } 8 | 9 | exports.funcOne = funcOne; 10 | exports.funcTwo = funcTwo; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/53920812/routes.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | 3 | var router = express.Router(); 4 | 5 | router.get('/', (req, res) => { 6 | res.sendStatus(200); 7 | }); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/53920812/server.js: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import router from './routes'; 3 | 4 | const app = express(); 5 | app.use(router); 6 | 7 | app.use((req, res, next) => { 8 | res.status(404).send('Sorry cant find that!'); 9 | }); 10 | 11 | const server = app.listen(3000, function() { 12 | var port = this.address().port; 13 | console.log('Example app listening on port %s!', port); 14 | }); 15 | 16 | export default server; 17 | -------------------------------------------------------------------------------- /src/stackoverflow/53934331/authService.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | export async function postAuthUser(auth) { 4 | return axios.post('https://github.com/mrdulin', auth); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/54230886/index.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | 3 | const app = express(); 4 | 5 | app.post('/api/users/auth/register', (req, res) => { 6 | res.status(400).json({ errArray: [] }); 7 | }); 8 | 9 | const port = 3001 || process.env.PORT; 10 | const server = app.listen(port, () => console.log(`Server running on port ${port}`)); 11 | 12 | export default server; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/54360588/dynamodb.js: -------------------------------------------------------------------------------- 1 | const AWS = require('aws-sdk'); 2 | const Promise = require('bluebird'); 3 | 4 | const client = new AWS.DynamoDB.DocumentClient(); 5 | 6 | module.exports.db = (method, params) => { 7 | console.log('access dynamodb'); 8 | return Promise.fromCallback((cb) => client[method](params, cb)); 9 | }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/54393006/index.ts: -------------------------------------------------------------------------------- 1 | import { NativeModules } from './react-native'; 2 | 3 | export function main() { 4 | return NativeModules.MyCustomNativeModule.dismiss(); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/54393006/react-native.ts: -------------------------------------------------------------------------------- 1 | const NativeModules = { 2 | MyCustomNativeModule: { 3 | dismiss: () => { 4 | // original implementation 5 | return 'real data'; 6 | } 7 | } 8 | }; 9 | 10 | export { NativeModules }; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/54456606/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`SearchComponent should search and filter job list correctly 1`] = `"
  • jdName: Senior/ Lead UI Developertechnology: java
"`; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/54587960/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`SearchFilter t1 1`] = `"
"`; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/54587960/actionCreators.ts: -------------------------------------------------------------------------------- 1 | export const SetFiltersValue = () => ({ type: 'SET_FILTER' }); 2 | -------------------------------------------------------------------------------- /src/stackoverflow/54622746/index.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | private age: number; 3 | private name: string; 4 | constructor(name: string, age: number) { 5 | this.name = name; 6 | this.age = age; 7 | } 8 | 9 | public goToSchool() { 10 | if (this.age > 16) { 11 | this.drive(); 12 | } else { 13 | this.takeBus(); 14 | } 15 | } 16 | 17 | public drive() { 18 | // ... 19 | } 20 | 21 | public takeBus() { 22 | // ... 23 | } 24 | } 25 | 26 | export { Student }; 27 | -------------------------------------------------------------------------------- /src/stackoverflow/54729837/third_party_module.js: -------------------------------------------------------------------------------- 1 | export default { 2 | func1() {} 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/54729837/util.js: -------------------------------------------------------------------------------- 1 | import moduleName from './third_party_module'; 2 | 3 | const util = { 4 | simple_function() { 5 | const name = moduleName.func1(); 6 | } 7 | }; 8 | 9 | export default util; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/54729837/util.spec.js: -------------------------------------------------------------------------------- 1 | import util from './util'; 2 | import moduleName from './third_party_module'; 3 | 4 | jest.mock('./third_party_module', () => ({ 5 | func1: jest.fn() 6 | })); 7 | 8 | describe('was mocked functions called', () => { 9 | test('was mocked functions called??', () => { 10 | util.simple_function(); 11 | expect(moduleName.func1).toHaveBeenCalled(); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /src/stackoverflow/54794512/index.tsx: -------------------------------------------------------------------------------- 1 | import { Component } from 'react'; 2 | import axios from 'axios'; 3 | 4 | class MyComponent extends Component { 5 | public async componentDidMount() { 6 | axios 7 | .get('https://jsonplaceholder.typicode.com/users') 8 | .then(res => res.data) 9 | .catch(err => 'catch error'); 10 | } 11 | 12 | public render() { 13 | return null; 14 | } 15 | } 16 | 17 | export default MyComponent; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/55127764/index.ts: -------------------------------------------------------------------------------- 1 | function connectDatabase(config) { 2 | switch (config.env) { 3 | case 'development': 4 | console.log('Connect to Dev DB'); 5 | break; 6 | case 'test': 7 | console.log('Connect to Test DB'); 8 | break; 9 | default: 10 | console.log('Connect to Prod DB'); 11 | break; 12 | } 13 | } 14 | 15 | export { connectDatabase }; 16 | -------------------------------------------------------------------------------- /src/stackoverflow/55228389/index.ts: -------------------------------------------------------------------------------- 1 | function mySessionSetFunction() { 2 | sessionStorage.setItem('name', 'jest'); 3 | } 4 | 5 | export { mySessionSetFunction }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/55302401/app.js: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import axios from 'axios'; 3 | 4 | const app = express(); 5 | 6 | app.get('/ping', (req, res) => { 7 | axios 8 | .get('/health') 9 | .then(() => { 10 | res.sendStatus(200); 11 | }) 12 | .catch((err) => { 13 | res.sendStatus(503); 14 | }); 15 | }); 16 | 17 | export default app; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/55766433/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Button = props => { 5 | return
; 6 | }; 7 | 8 | Button.propTypes = { 9 | action: PropTypes.string.isRequired, 10 | path: PropTypes.string.isRequired 11 | }; 12 | 13 | export default Button; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/55767756/TableName.ts: -------------------------------------------------------------------------------- 1 | export class TableName { 2 | constructor(opts) {} 3 | async save() { 4 | return this; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/stackoverflow/55767756/index.ts: -------------------------------------------------------------------------------- 1 | import { TableName } from './TableName'; 2 | 3 | export async function main() { 4 | const hashkey = 'hashkey'; 5 | const rangekey = 'rangekey'; 6 | const moreItems = {}; 7 | const tableName = await new TableName({ 8 | hashkey, 9 | rangekey, 10 | ...moreItems 11 | }).save(); 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/55787988/index.spec.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './'; 4 | 5 | describe('App', () => { 6 | it('renders without crashing', () => { 7 | window.alert = jest.fn(); 8 | const div = document.createElement('div'); 9 | ReactDOM.render(, div); 10 | expect(window.alert).toBeCalledWith('haha'); 11 | ReactDOM.unmountComponentAtNode(div); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /src/stackoverflow/55787988/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class App extends Component { 4 | componentDidMount() { 5 | window.alert('haha'); 6 | } 7 | render() { 8 | return
; 9 | } 10 | } 11 | 12 | export default App; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/55789099/custom-http-client.ts: -------------------------------------------------------------------------------- 1 | export default class HttpClient { 2 | public async get(url) { 3 | return 'real data'; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/55789099/getIntentsSince.ts: -------------------------------------------------------------------------------- 1 | import HttpClient from './custom-http-client'; 2 | 3 | const client = new HttpClient(); 4 | 5 | const getIntentsSince = (currentTime, fromIntervalTime) => { 6 | return client.get(`url`).then(data => { 7 | return data; 8 | }); 9 | }; 10 | 11 | export default getIntentsSince; 12 | -------------------------------------------------------------------------------- /src/stackoverflow/55828418/service.ts: -------------------------------------------------------------------------------- 1 | const Api = { 2 | async post(url) { 3 | return { data: { data: 'real data' } }; 4 | } 5 | }; 6 | 7 | export class Service { 8 | public uploadSomething = filename => { 9 | return Api.post('/test') 10 | .then(response => { 11 | return response.data; 12 | }) 13 | .catch(error => { 14 | return Promise.reject(error); 15 | }); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/stackoverflow/55838798/index.ts: -------------------------------------------------------------------------------- 1 | import moment from 'moment'; 2 | 3 | export function main() { 4 | return { 5 | currentDateMoment: moment().format(), 6 | currentDateFormatted: moment() 7 | .format('MM-DD-YYYY') 8 | .valueOf() 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /src/stackoverflow/55936794/discount.ts: -------------------------------------------------------------------------------- 1 | export const discount = { 2 | put(obj) { 3 | return obj; 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/55936794/index.ts: -------------------------------------------------------------------------------- 1 | import { discount } from './discount'; 2 | 3 | export const ADD_DISCOUNT = { 4 | triplet: 'triplet' 5 | }; 6 | 7 | export const addDiscount = ({ code }) => (dispatch, getState) => { 8 | const { id } = getState().token; 9 | 10 | return dispatch({ 11 | apiCall: discount.put({ body: { code }, id }), 12 | types: ADD_DISCOUNT.triplet 13 | }); 14 | }; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/55966274/types.ts: -------------------------------------------------------------------------------- 1 | export const BG_LOAD_START = 'BG_LOAD_START'; 2 | export const BG_LOAD_SUCCESS = 'BG_LOAD_SUCCESS'; 3 | export const BG_LOAD_FAILURE = 'BG_LOAD_FAILURE'; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/56011077/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class SomeComponent extends Component { 4 | render() { 5 | return
; 6 | } 7 | } 8 | 9 | export default SomeComponent; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/56014527/app.js: -------------------------------------------------------------------------------- 1 | const work = require('./work'); 2 | const express = require('express'); 3 | 4 | const app = express(); 5 | 6 | app.use(work).get('/', (req, res) => { 7 | res.sendStatus(200); 8 | }); 9 | 10 | module.exports = app; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/56014527/work.js: -------------------------------------------------------------------------------- 1 | function work(req, res, next) { 2 | next(); 3 | } 4 | 5 | module.exports = work; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/56238887/PolicyModels.ts: -------------------------------------------------------------------------------- 1 | export function patchWork(...args) {} 2 | 3 | export function patchWorkContext(...args) {} 4 | -------------------------------------------------------------------------------- /src/stackoverflow/56281185/DataService.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | class DataService { 4 | public static async getdata() { 5 | return axios.get(`https://github.com/mrdulin`).then(() => { 6 | return { 7 | name: 'real name', 8 | key: 'real key', 9 | expiration: null 10 | }; 11 | }); 12 | } 13 | } 14 | 15 | export { DataService }; 16 | -------------------------------------------------------------------------------- /src/stackoverflow/56354252/index.spec.ts: -------------------------------------------------------------------------------- 1 | describe('test function2 ', () => { 2 | const helperFunctions = require('./'); 3 | helperFunctions.function1 = jest.fn(); 4 | test('test', () => { 5 | helperFunctions.function1.mockReturnValueOnce(1); 6 | expect(helperFunctions.function2()).toEqual(3); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /src/stackoverflow/56354252/index.ts: -------------------------------------------------------------------------------- 1 | const function1 = () => { 2 | return 123; 3 | }; 4 | const function2 = () => { 5 | return exports.function1() + 2; 6 | }; 7 | 8 | exports.function1 = function1; 9 | exports.function2 = function2; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/56410688/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`DisplayData should not fetch data when query is empty string 1`] = `
    `; 4 | 5 | exports[`DisplayData should show new entries when query is set 1`] = ` 6 | 15 | `; 16 | -------------------------------------------------------------------------------- /src/stackoverflow/56425230/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Header match snapshot 1`] = ` 4 |
    5 | 2019-11-24T00:00:00.000Z 6 |
    7 | `; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/56425230/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import moment from 'moment'; 3 | 4 | export class Header extends React.Component { 5 | public render() { 6 | const date = moment() 7 | .month(10) 8 | .date(24) 9 | .utc(); 10 | 11 | return
    {date.toISOString()}
    ; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/stackoverflow/56446543/index.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from 'dotenv'; 2 | 3 | export class TestSubject { 4 | public test() { 5 | console.log(dotenv); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/stackoverflow/56482707/StudentServices.ts: -------------------------------------------------------------------------------- 1 | export class StudentServices { 2 | public static async getCollegeurl(id: string) { 3 | return { 4 | data: { 5 | collegeurl: 'real url' 6 | } 7 | }; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/stackoverflow/56546760/index.ts: -------------------------------------------------------------------------------- 1 | function checkEnvironmentVars() { 2 | if (!process.env.NODE_ENV) { 3 | throw Error('Process environment is required!'); 4 | } 5 | 6 | const allowedEnvironments = ['local', 'development', 'production']; 7 | 8 | if (!allowedEnvironments.includes(process.env.NODE_ENV)) { 9 | throw Error('Process environment not allowed! Choose another!'); 10 | } 11 | } 12 | 13 | export { checkEnvironmentVars }; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/56674440/Models.ts: -------------------------------------------------------------------------------- 1 | import console = require('console'); 2 | 3 | export async function patchAccount(...args) { 4 | return { error: true }; 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/56730186/privateRoute.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Route, Redirect } from 'react-router'; 3 | 4 | function PrivateRoute({ authenticated, ownProps }) { 5 | const { component: Component, ...rest } = ownProps; 6 | return (authenticated ? : )} />; 7 | } 8 | 9 | export default PrivateRoute; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/56821395/index.js: -------------------------------------------------------------------------------- 1 | const aws = require('aws-sdk'); 2 | aws.config.update({ region: 'us-east-1' }); 3 | const ssm = new aws.SSM(); 4 | const baseSsm = `/mybox/`; 5 | 6 | module.exports = { 7 | async getSsmVar(name) { 8 | const params = { 9 | Name: baseSsm + name, 10 | WithDecryption: true 11 | }; 12 | const request = await ssm.getParameter(params).promise(); 13 | return request; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /src/stackoverflow/56847385/index.ts: -------------------------------------------------------------------------------- 1 | export interface INewArtist { 2 | name: string; 3 | title: string | null; 4 | } 5 | 6 | export interface IDocument { 7 | metadata: { 8 | artist: INewArtist; 9 | }; 10 | } 11 | 12 | export class MyTestClass { 13 | constructor(private readonly ctx) {} 14 | public async map(document: IDocument) { 15 | const artist: INewArtist = document.metadata.artist; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/stackoverflow/56847791/serverErrorResponseUtil.ts: -------------------------------------------------------------------------------- 1 | export interface HttpError { 2 | message: string; 3 | } 4 | 5 | export function serverErrorResponseUtil(error: HttpError) { 6 | return new Error(error.message); 7 | } 8 | -------------------------------------------------------------------------------- /src/stackoverflow/56924299/HttpResponse.ts: -------------------------------------------------------------------------------- 1 | class HttpResponse { 2 | public status = 0; 3 | public setSuccess(status, message, payload) { 4 | this.status = status; 5 | } 6 | public setReject(...args) {} 7 | } 8 | 9 | export default HttpResponse; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/56924299/bcrypt.ts: -------------------------------------------------------------------------------- 1 | const bcrypt = { 2 | async hash(...args) { 3 | return 'real hash'; 4 | } 5 | }; 6 | 7 | export default bcrypt; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/56924299/config.ts: -------------------------------------------------------------------------------- 1 | const config = { saltRounds: '123' }; 2 | 3 | export default config; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/56924299/dbSessionModule.ts: -------------------------------------------------------------------------------- 1 | class DbSessionModule { 2 | public async connect() { 3 | return {}; 4 | } 5 | public async release() { 6 | return {}; 7 | } 8 | } 9 | 10 | export default DbSessionModule; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/56924299/signupModule.ts: -------------------------------------------------------------------------------- 1 | const signupModule = { 2 | async createAccount(...args) { 3 | return { accountId: 2222 }; 4 | } 5 | }; 6 | 7 | export default signupModule; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/56942805/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { functionToBeTested } from './'; 2 | 3 | jest.useFakeTimers(); 4 | 5 | test('should return correctly', async () => { 6 | const logSpy = jest.spyOn(console, 'log'); 7 | const promise = functionToBeTested(); 8 | jest.runAllTimers(); 9 | await expect(promise).resolves.toBe('anything'); 10 | expect(logSpy).toBeCalledWith('not logging :/'); 11 | }); 12 | -------------------------------------------------------------------------------- /src/stackoverflow/56942805/index.ts: -------------------------------------------------------------------------------- 1 | export const functionToBeTested = () => { 2 | return new Promise(resolve => { 3 | setTimeout(() => { 4 | console.log('not logging :/'); 5 | resolve('anything'); 6 | }, 1000); 7 | }); 8 | }; 9 | -------------------------------------------------------------------------------- /src/stackoverflow/56960035/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export const Avatar = ({ imageSrc, imageAlt, imageWidth, imageHeight }) => ( 4 | {imageAlt} { 9 | // @ts-ignore 10 | e.target.src = '/static/images/placeholder/avatar.png'; 11 | }} 12 | /> 13 | ); 14 | -------------------------------------------------------------------------------- /src/stackoverflow/56961691/index.ts: -------------------------------------------------------------------------------- 1 | const { setupUserAccounts } = require('./shared/user'); 2 | 3 | export function main() { 4 | return setupUserAccounts(); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/56961691/shared/user/index.ts: -------------------------------------------------------------------------------- 1 | exports.setupUserAccounts = config => { 2 | console.log('setupUserAccounts'); 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/57087200/index.spec.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | import { getCustomer } from './'; 3 | 4 | describe('getCustomer', () => { 5 | it('t1', async () => { 6 | const url = 'https://github.com/mrdulin'; 7 | axios.patch = jest.fn().mockResolvedValueOnce({ status: 202 }); 8 | const actualValue = await getCustomer(); 9 | expect(actualValue).toEqual({ status: 202 }); 10 | expect(axios.patch).toBeCalledWith(url, { customerId: '12345' }); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/57087200/index.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | async function getCustomer() { 4 | const url = 'https://github.com/mrdulin'; 5 | const result = await axios.patch(url, { customerId: '12345' }); 6 | return result; 7 | } 8 | 9 | export { getCustomer }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/57088724/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { createLink, document, Link } from './'; 2 | 3 | describe('createLink', () => { 4 | it('t1', () => { 5 | const url = 'https://github.com/mrdulin'; 6 | jest.spyOn(document, 'createElement').mockReturnValueOnce(new Link('mock link')); 7 | const link = createLink(url); 8 | expect(link).toBeInstanceOf(Link); 9 | expect(link.href).toBe(url); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/stackoverflow/57092154/index.ts: -------------------------------------------------------------------------------- 1 | function funcToTest(imgUrl, callback) { 2 | const img = new Image(); 3 | img.src = imgUrl; 4 | 5 | img.onload = () => { 6 | callback(true); // should return callback with true on finish 7 | }; 8 | 9 | img.onerror = e => { 10 | callback(false); // should return callback with false on error 11 | console.log(e); 12 | }; 13 | 14 | return img; 15 | } 16 | 17 | export { funcToTest }; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/57154476/HeaderBar.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import HeaderBar from './HeaderBar'; 3 | import { shallow } from 'enzyme'; 4 | 5 | it('mocks the search function', () => { 6 | const logSpy = jest.spyOn(console, 'log'); 7 | const wrapper = shallow(); 8 | const mEvent = { target: 'fake target' }; 9 | wrapper.find('div').simulate('click', mEvent); 10 | expect(logSpy).toBeCalledWith(mEvent); 11 | }); 12 | -------------------------------------------------------------------------------- /src/stackoverflow/57154476/HeaderBar.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const HeaderBar = (props: any) => { 4 | const search = e => { 5 | console.log(e); 6 | }; 7 | return
    ; 8 | }; 9 | 10 | export default HeaderBar; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/57172774/service.ts: -------------------------------------------------------------------------------- 1 | class Service { 2 | public get() { 3 | return 'real data'; 4 | } 5 | public post() {} 6 | public del() {} 7 | public doThis() { 8 | console.log('real do this'); 9 | return this.get(); 10 | } 11 | } 12 | export { Service }; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/57248527/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Comp t1 1`] = `"
    test
    "`; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/57248527/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export const Comp = ({ OnItemsUpdate, items, datasource }) => { 4 | Promise.all( 5 | items.map(item => { 6 | return datasource.UpdateItem(item); 7 | }) 8 | ).then(() => { 9 | return OnItemsUpdate(); 10 | }); 11 | 12 | // not including rest of the component for brevity's sake 13 | return
    test
    ; 14 | }; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/57290601/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`test t1 1`] = `"
    1
    "`; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/57322103/index.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class SomeComponent extends Component { 4 | componentDidMount() { 5 | this.props.actions.getSomething(); 6 | } 7 | render() { 8 | return
    ; 9 | } 10 | } 11 | 12 | export default SomeComponent; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/57353993/app.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | const xmlparser = require('express-xml-bodyparser'); 4 | 5 | app.use(xmlparser()); 6 | app.post('/', (req, res) => { 7 | res.json(req.body); 8 | }); 9 | 10 | module.exports = app; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/57394312/index.ts: -------------------------------------------------------------------------------- 1 | export const downloadWithLink = (imgDataUrl, fileName) => { 2 | const link = document.createElement('a'); 3 | link.href = imgDataUrl; 4 | document.body.appendChild(link); 5 | link.click(); 6 | document.body.removeChild(link); 7 | }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/57410473/OriginalClass.ts: -------------------------------------------------------------------------------- 1 | export class OriginalClass { 2 | public static call() { 3 | return 'real data'; 4 | } 5 | 6 | public static testCall() { 7 | return this.call(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/stackoverflow/57428542/Agent.ts: -------------------------------------------------------------------------------- 1 | interface DialogFlowPayload {} 2 | interface WebhookClient {} 3 | interface Chatter { 4 | getMessage(): any; 5 | } 6 | class Agent { 7 | private payload: DialogFlowPayload[] = []; 8 | 9 | constructor(readonly webhookClient: WebhookClient, private readonly chatter: Chatter) {} 10 | 11 | public getParameter() { 12 | return 'real data'; 13 | } 14 | 15 | public otherMethod() { 16 | return 'other real data'; 17 | } 18 | } 19 | 20 | export { Agent, Chatter }; 21 | -------------------------------------------------------------------------------- /src/stackoverflow/57428542/extractPayloadDates.ts: -------------------------------------------------------------------------------- 1 | function extractPayloadDates(agent) { 2 | return agent.getParameter(); 3 | } 4 | 5 | export { extractPayloadDates }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/57461614/index.ts: -------------------------------------------------------------------------------- 1 | import { socket } from './socket'; 2 | 3 | export const obj = { 4 | someMethod() { 5 | this.handleFerret = this.handleFerret.bind(this); 6 | socket.emit('ferret', 'tobi', this.handleFerret); 7 | }, 8 | 9 | handleFerret(data) { 10 | const a = 5; 11 | this.sum(a, data); 12 | }, 13 | 14 | sum(a, b) { 15 | // 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/57461614/socket.ts: -------------------------------------------------------------------------------- 1 | export const socket = { 2 | emit(event, data, callback) { 3 | // real implemetation 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/57492604/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { Service, FundMock } from '.'; 2 | 3 | const service = new Service(); 4 | 5 | describe('Service', () => { 6 | describe('#getFund', () => { 7 | it('t1', async () => { 8 | service.getFund = jest.fn().mockResolvedValueOnce(FundMock); 9 | const actualValue = await service.getFund(); 10 | expect(actualValue).toEqual(FundMock); 11 | }); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /src/stackoverflow/57494989/__mocks__/loadDataFromLocalStorage.ts: -------------------------------------------------------------------------------- 1 | function loadDataFromLocalStorage() { 2 | return () => { 3 | return 'mock data'; 4 | }; 5 | } 6 | 7 | export default loadDataFromLocalStorage; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/57494989/index.spec.ts: -------------------------------------------------------------------------------- 1 | jest.mock('./loadDataFromLocalStorage.ts'); 2 | import { someModule } from '.'; 3 | 4 | describe('someModule', () => { 5 | it('t1', () => { 6 | expect.assertions(1); 7 | const actualValue = someModule.myFunc(); 8 | expect(actualValue).toBeTruthy(); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/stackoverflow/57494989/index.ts: -------------------------------------------------------------------------------- 1 | import loadDataFromLocalStorage from './loadDataFromLocalStorage'; 2 | 3 | const someModule = { 4 | myFunc() { 5 | const data = loadDataFromLocalStorage()(); 6 | console.log(`data: ${data}`); 7 | if (data) { 8 | return true; 9 | } 10 | } 11 | }; 12 | 13 | export { someModule }; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/57494989/loadDataFromLocalStorage.ts: -------------------------------------------------------------------------------- 1 | function loadDataFromLocalStorage() { 2 | return () => { 3 | return ''; 4 | }; 5 | } 6 | 7 | export default loadDataFromLocalStorage; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/57515192/Db.ts: -------------------------------------------------------------------------------- 1 | import console = require('console'); 2 | 3 | export class Db { 4 | public connection = { 5 | collection(model: string) { 6 | return { 7 | async updateOne(...args) { 8 | console.log('update one'); 9 | } 10 | }; 11 | } 12 | }; 13 | public async connect() { 14 | console.log('connect db'); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/stackoverflow/57515192/example.ts: -------------------------------------------------------------------------------- 1 | import { Db } from './Db'; 2 | 3 | const db = new Db(); 4 | 5 | export async function example(id) { 6 | await db.connect().catch(err => console.error(err)); 7 | const Data = db.connection.collection('data'); 8 | 9 | return Data.updateOne({ id }, { $set: { anything: 'else' } }).catch(err => console.error(err)); 10 | } 11 | -------------------------------------------------------------------------------- /src/stackoverflow/57593767/auth.js: -------------------------------------------------------------------------------- 1 | async function auth() { 2 | return 'real auth response'; 3 | } 4 | module.exports = { auth }; 5 | -------------------------------------------------------------------------------- /src/stackoverflow/57593767/utils.js: -------------------------------------------------------------------------------- 1 | let { auth } = require('./auth'); 2 | 3 | let authToken = undefined; 4 | 5 | const checkIfTokenIsValid = async () => { 6 | if (authToken) { 7 | authToken = await auth(); 8 | } 9 | }; 10 | 11 | module.exports = { 12 | checkIfTokenIsValid, 13 | }; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/57614415/UploadHandler.ts: -------------------------------------------------------------------------------- 1 | export default class UploadHandler { 2 | constructor(opts) {} 3 | 4 | public async uploadFile(opt) { 5 | console.log('uploadFile'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/stackoverflow/57624975/a.spec.ts: -------------------------------------------------------------------------------- 1 | import { A } from './a'; 2 | 3 | describe('A', () => { 4 | describe('checkTesting', () => { 5 | it('should initiate the constructor', () => { 6 | jest.spyOn(A, 'checkTesting').mockReturnValue({ name: 'never mind' }); 7 | const param = 'one'; 8 | const a = new A(param); 9 | expect(a).toBeInstanceOf(A); 10 | expect(A.checkTesting).toBeCalledWith(param); 11 | }); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /src/stackoverflow/57624975/a.ts: -------------------------------------------------------------------------------- 1 | import one from './one'; 2 | import two from './two'; 3 | import three from './three'; 4 | 5 | class A { 6 | public static checkTesting(param) { 7 | switch (param) { 8 | case 'one': 9 | return one; 10 | case 'two': 11 | return two; 12 | default: 13 | return three; 14 | } 15 | } 16 | private testing; 17 | constructor(param) { 18 | this.testing = A.checkTesting(param); 19 | } 20 | } 21 | 22 | export { A }; 23 | -------------------------------------------------------------------------------- /src/stackoverflow/57624975/one.ts: -------------------------------------------------------------------------------- 1 | export default { name: 'one' }; 2 | -------------------------------------------------------------------------------- /src/stackoverflow/57624975/three.ts: -------------------------------------------------------------------------------- 1 | export default { name: 'three' }; 2 | -------------------------------------------------------------------------------- /src/stackoverflow/57624975/two.ts: -------------------------------------------------------------------------------- 1 | export default { name: 'two' }; 2 | -------------------------------------------------------------------------------- /src/stackoverflow/57649917/index.ts: -------------------------------------------------------------------------------- 1 | export class SomeClass { 2 | find() { 3 | console.log('find'); 4 | } 5 | findById(id) { 6 | console.log('findById'); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/stackoverflow/57660437/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Header t1 1`] = ` 4 |
    5 | 2019-08-26T11:55:03.696Z 6 |
    7 | `; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/57660437/requestService.ts: -------------------------------------------------------------------------------- 1 | export async function runningSince() { 2 | return { 3 | data: { 4 | runningSince: 'real data' 5 | } 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /src/stackoverflow/57673447/ActivationUI.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export const ActivationUI = ({ context, messages }) =>
    ActivationUI
    ; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/57673447/ExternalLandingPageUtil.ts: -------------------------------------------------------------------------------- 1 | export const ExternalLandingPageUtil = { 2 | getExternalLandingPageUrl(context) { 3 | return context.externalLP; 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/57674824/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`SomeCompoennt should call reloadObjectDetails when objectId has changed 1`] = ` 4 |
    5 | 123 6 |
    7 | `; 8 | 9 | exports[`SomeCompoennt should shallow render correctly 1`] = ` 10 |
    11 | 12 12 |
    13 | `; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/57704755/apiClient.ts: -------------------------------------------------------------------------------- 1 | const apiClient = { 2 | get: async parameter => { 3 | return 'real data'; 4 | } 5 | }; 6 | 7 | export { apiClient }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/57704755/index.ts: -------------------------------------------------------------------------------- 1 | import { apiClient } from './apiClient'; 2 | 3 | async function main(parameter) { 4 | try { 5 | const res = await apiClient.get(parameter); 6 | console.log(res); 7 | return res; 8 | } catch (error) { 9 | throw new Error('get error'); 10 | } 11 | } 12 | 13 | export { main }; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/57712713/index.js: -------------------------------------------------------------------------------- 1 | const { Viewer } = require('./viewer'); 2 | const util = require('./util'); 3 | 4 | module.exports = { 5 | createViewer: container => { 6 | if (util.isElement(container)) { 7 | return new Viewer(container); 8 | } else { 9 | throw new Error('Invalid Element when attempting to create underlying viewer.'); 10 | } 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/57712713/util.js: -------------------------------------------------------------------------------- 1 | const util = { 2 | isElement() {} 3 | }; 4 | 5 | module.exports = util; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/57712713/viewer.js: -------------------------------------------------------------------------------- 1 | function Viewer() { 2 | // Doing things 3 | console.log('new viewer instance'); 4 | } 5 | 6 | Viewer.prototype.foo = function() {}; 7 | 8 | module.exports = { Viewer }; 9 | -------------------------------------------------------------------------------- /src/stackoverflow/57719741/client.ts: -------------------------------------------------------------------------------- 1 | const client = { 2 | items: () => { 3 | return client; 4 | }, 5 | type: (name: string) => { 6 | return client; 7 | }, 8 | toObservable: () => { 9 | return client; 10 | }, 11 | subscribe: handler => { 12 | handler(); 13 | return client; 14 | } 15 | }; 16 | 17 | export { client }; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/57719741/index.ts: -------------------------------------------------------------------------------- 1 | class Component { 2 | private props; 3 | constructor(props) { 4 | this.props = props; 5 | } 6 | public componentDidMount() { 7 | this.props.client 8 | .items() 9 | .type('client') 10 | .toObservable() 11 | .subscribe(response => { 12 | this.setState(response); 13 | }); 14 | } 15 | private setState(state) { 16 | console.log(state); 17 | } 18 | } 19 | 20 | export { Component }; 21 | -------------------------------------------------------------------------------- /src/stackoverflow/57730153/actionCreators.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | export const getOddGroups = () => { 4 | return dispatch => { 5 | return axios 6 | .get('/api/tables/oddgroups') 7 | .then(results => { 8 | dispatch({ type: 'GET_ODD_GROUPS', payload: results.data }); 9 | }) 10 | .catch(err => { 11 | dispatch({ type: 'GET_ERRORS', payload: err.response.message }); 12 | }); 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/57775960/__mocks__/someService.ts: -------------------------------------------------------------------------------- 1 | const mockedSomeService = { 2 | saveNewElement: jest.fn().mockResolvedValue('mocked data') 3 | }; 4 | const SomeService = jest.fn(() => mockedSomeService); 5 | 6 | export { SomeService, mockedSomeService }; 7 | -------------------------------------------------------------------------------- /src/stackoverflow/57775960/index.spec.ts: -------------------------------------------------------------------------------- 1 | import UnderTest from './'; 2 | 3 | jest.mock('./someService.ts'); 4 | 5 | const underTest = new UnderTest(); 6 | 7 | describe('UnderTest', () => { 8 | it('t1', async () => { 9 | console.log = jest.fn(); 10 | await underTest.update('jest'); 11 | expect(console.log).toBeCalledWith('mocked data'); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /src/stackoverflow/57775960/index.ts: -------------------------------------------------------------------------------- 1 | import { SomeService } from './someService'; 2 | 3 | export default class UnderTest { 4 | private service: SomeService; 5 | 6 | constructor() { 7 | this.service = new SomeService(); 8 | } 9 | 10 | public update(data: any): any { 11 | return this.service.saveNewElement(data).then(res => { 12 | // stuff to do 13 | console.log(res); 14 | }); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/stackoverflow/57775960/someService.ts: -------------------------------------------------------------------------------- 1 | class SomeService { 2 | public async saveNewElement(data) { 3 | return 'real data'; 4 | } 5 | } 6 | 7 | export { SomeService }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/57778786/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`myComponent should renders correctly 1`] = ` 4 |
    5 | rows count: 6 | 3 7 |
    8 | `; 9 | -------------------------------------------------------------------------------- /src/stackoverflow/57797518/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from 'react'; 2 | 3 | const Compo = ({ funcA }) => { 4 | useEffect(() => { 5 | window.addEventListener('x', funcB, false); 6 | 7 | return () => { 8 | window.removeEventListener('x', funcB, false); 9 | }; 10 | }, []); 11 | 12 | const funcB = () => { 13 | funcA(); 14 | }; 15 | 16 | return 16 | ); 17 | }; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/57810999/downloadCSV.ts: -------------------------------------------------------------------------------- 1 | export function downloadCSV(csv: string, filename: string) { 2 | let csvFile; 3 | let downloadLink; 4 | 5 | csvFile = new Blob([csv], { type: 'text/csv' }); 6 | downloadLink = document.createElement('a'); 7 | downloadLink.download = filename; 8 | downloadLink.href = window.URL.createObjectURL(csvFile); 9 | downloadLink.style.display = 'none'; 10 | document.body.appendChild(downloadLink); 11 | downloadLink.click(); 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/57811289/index.ts: -------------------------------------------------------------------------------- 1 | interface IKnex { 2 | where(...args: any): any; 3 | raw(...args: any): any; 4 | select(...args: any): any; 5 | then(): any; 6 | } 7 | 8 | class SomeDaoImpl { 9 | private knex: IKnex; 10 | constructor({ knex }) { 11 | this.knex = knex; 12 | } 13 | public findById(id: string) { 14 | return this.knex.where({ id }).select(); 15 | } 16 | } 17 | 18 | export { SomeDaoImpl, IKnex }; 19 | -------------------------------------------------------------------------------- /src/stackoverflow/57835066/index.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | function main() { 4 | return axios 5 | .get('url') 6 | .then(res => { 7 | console.log(res); 8 | }) 9 | .catch(err => { 10 | console.log(err); 11 | }); 12 | } 13 | 14 | export { main }; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/57847401/testfunction.ts: -------------------------------------------------------------------------------- 1 | async function testfunction(userParams, successCallback, errorCallback) { 2 | return { 3 | type: 'ACTION_TYPE', 4 | payload: {} 5 | }; 6 | } 7 | export { testfunction }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/57850379/index.js: -------------------------------------------------------------------------------- 1 | function chunk(array, size) { 2 | const chunked = new Array(); // change this to [] the test pass 3 | 4 | for (let i = 0, j = 0; i < array.length; i += size, j++) { 5 | chunked[j] = array.slice(i, i + size); // remove index j and use push() method test pass 6 | } 7 | 8 | return chunked; 9 | } 10 | 11 | module.exports = chunk; 12 | -------------------------------------------------------------------------------- /src/stackoverflow/57850379/index.spec.js: -------------------------------------------------------------------------------- 1 | const chunk = require('./index'); 2 | 3 | describe('Chunk function', () => { 4 | test('should correctly divide an array of 10 elements with chunk size 2', () => { 5 | const chunked = chunk([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2); 6 | expect(chunked).toEqual([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /src/stackoverflow/57931751/index.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | const user = 'user'; 4 | 5 | export const Users = { 6 | getUser: async id => { 7 | const result = await axios.get(`${user + id}.json`).then(({ data }) => data); 8 | return result; 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/57942218/ProductListItem.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export default function ProductListItem(props) { 4 | return
    ProductListItem
    ; 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/57960039/service.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable-next-line: interface-name 2 | export interface ClientProxy { 3 | send(pattern: string, simulation: any): any; 4 | connect(): any; 5 | close(): any; 6 | routingMap(): any; 7 | } 8 | 9 | export class SimulationsService { 10 | constructor(private simulationClient: ClientProxy) {} 11 | 12 | public method1() { 13 | const simulation = {}; 14 | this.simulationClient.send('simulatePattern', simulation); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/stackoverflow/57963177/index.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | 3 | const app = express(); 4 | 5 | app.get('/test-with-token', async (req, res) => { 6 | res.set('token', '123'); 7 | res.sendStatus(200); 8 | }); 9 | 10 | app.get('/test', async (req, res) => { 11 | res.sendStatus(200); 12 | }); 13 | 14 | export default app; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/57992553/axiosConfig.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | const apiClient = axios.create({ 3 | baseURL: `${process.env.VUE_APP_ROOT_API}` 4 | }); 5 | 6 | export default apiClient; 7 | -------------------------------------------------------------------------------- /src/stackoverflow/57992553/interfaces/Approval.ts: -------------------------------------------------------------------------------- 1 | interface Approval {} 2 | 3 | export default Approval; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/58048849/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`AccountCheckModule should render correct 1`] = ` 4 |
    5 |
    6 | 666 7 |
    8 |
    9 | `; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/58048849/electron.ts: -------------------------------------------------------------------------------- 1 | export const ipcRenderer = { 2 | events: {}, 3 | on(event, handler) { 4 | this.events[event] = handler; 5 | }, 6 | send(event, data) { 7 | this.events[event](event, data); 8 | }, 9 | removeAllListeners(event) { 10 | this.events[event] = undefined; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/58049595/First.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import TelemetryFramework from './TelemetryFramework'; 3 | 4 | class First extends TelemetryFramework { 5 | constructor(props) { 6 | super(props); 7 | } 8 | public getData() { 9 | const data = this.getconfidentialData(); 10 | this.telemetryInfo('data fetched..'); 11 | } 12 | public render() { 13 | return
    First
    ; 14 | } 15 | } 16 | 17 | export default First; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/58049595/TelemetryFramework.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class TelemetryFramework extends Component { 4 | public render() { 5 | return
    TelemetryFramework
    ; 6 | } 7 | protected telemetryInfo(...args: any[]) { 8 | // 9 | } 10 | protected getconfidentialData() { 11 | // 12 | } 13 | } 14 | 15 | export default TelemetryFramework; 16 | -------------------------------------------------------------------------------- /src/stackoverflow/58059957/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | interface ICheckStateState { 4 | isDone: boolean; 5 | } 6 | 7 | export class CheckState extends React.Component<{}, ICheckStateState> { 8 | constructor(props) { 9 | super(props); 10 | this.state = { 11 | isDone: false 12 | }; 13 | } 14 | 15 | public render() { 16 | if (this.state.isDone) { 17 | return
    Done
    ; 18 | } else { 19 | return
    Not Done
    ; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/stackoverflow/58073589/dependency-service-instance.ts: -------------------------------------------------------------------------------- 1 | import { DependencyService } from './dependency-service'; 2 | 3 | export const dependendantService = new DependencyService(); 4 | -------------------------------------------------------------------------------- /src/stackoverflow/58073589/dependency-service.ts: -------------------------------------------------------------------------------- 1 | export class DependencyService { 2 | private _list: any[] = []; 3 | public get list(): any[] { 4 | return this._list; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/stackoverflow/58073589/my-service.ts: -------------------------------------------------------------------------------- 1 | import { dependendantService } from './dependency-service-instance'; 2 | 3 | export function myFunction(): string { 4 | const list = dependendantService.list; 5 | if (!list.length) { 6 | throw new Error('list is empty'); 7 | } 8 | return 'xyz'; 9 | } 10 | -------------------------------------------------------------------------------- /src/stackoverflow/58082922/api.ts: -------------------------------------------------------------------------------- 1 | export const api = { 2 | async getVehicles() { 3 | return { vehicles: [{ active: true }] }; 4 | }, 5 | 6 | async getCurrentMoto() { 7 | return { name: 'real name' }; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/58107885/client.ts: -------------------------------------------------------------------------------- 1 | export interface myClient { 2 | getClient: (customerId: string) => Promise; 3 | } 4 | 5 | const impClient = (): myClient => { 6 | return { 7 | getClient: async (customerId: string) => { 8 | return customerId; 9 | } 10 | }; 11 | }; 12 | 13 | export default impClient; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/58107885/main.ts: -------------------------------------------------------------------------------- 1 | import impClient from './client'; 2 | 3 | export function main(customerId) { 4 | return impClient().getClient(customerId); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58110463/ajaxService.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | export const AjaxService = { 4 | post: (url, data, headers?) => { 5 | return axios({ 6 | method: 'POST', 7 | url, 8 | headers: headers || { 'content-type': 'application/json' }, 9 | data 10 | }); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/58110463/service.ts: -------------------------------------------------------------------------------- 1 | import { AjaxService } from './ajaxService'; 2 | 3 | export const userLogin = data => { 4 | return AjaxService.post('http://localhost/3000/signin', data).then( 5 | res => { 6 | return res.data; 7 | }, 8 | error => { 9 | return error.response.data; 10 | } 11 | ); 12 | }; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/58239972/Vue.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | notify(payload) { 3 | // 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58244855/.tmp/genericCsv.csv: -------------------------------------------------------------------------------- 1 | aa -------------------------------------------------------------------------------- /src/stackoverflow/58244855/index.ts: -------------------------------------------------------------------------------- 1 | export class SomeClass { 2 | async functionToTest(stream) { 3 | // Run some checks on the stream here 4 | stream 5 | .on('data', async data => { 6 | // Run some checks on the data here 7 | await this.processStreamData(data); 8 | }) 9 | .on('finish', () => { 10 | // Do some processing here 11 | Promise.resolve(); 12 | }); 13 | } 14 | 15 | async processStreamData(data) { 16 | console.log(data); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/stackoverflow/58273544/index.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | export async function getUserDataByIds(ids: string[]) { 4 | try { 5 | const users = await axios.get('/users'); 6 | return users; 7 | } catch (err) { 8 | return new Map(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/stackoverflow/58310060/index.spec.ts: -------------------------------------------------------------------------------- 1 | const foo = (): void => 2 | test('this is a test', () => { 3 | expect(true).toBeTruthy(); 4 | }); 5 | 6 | describe('test suites', () => { 7 | foo(); 8 | }); 9 | -------------------------------------------------------------------------------- /src/stackoverflow/58357043/index.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | const getAreas = area => axios.get(`/test/areas/${area}`); 4 | 5 | export default getAreas; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58365044/index.ts: -------------------------------------------------------------------------------- 1 | export function render() { 2 | if (document.body.getAttribute('data-basepath') === 'coolvalue') { 3 | return 'My Component'; 4 | } 5 | return null; 6 | } 7 | -------------------------------------------------------------------------------- /src/stackoverflow/58396438/actionCreator.ts: -------------------------------------------------------------------------------- 1 | import { apiCall } from './apiCall'; 2 | 3 | export const ACTION_TYPE = 'ACTION_TYPE'; 4 | 5 | export const someAction = id => async dispatch => { 6 | try { 7 | const { data } = await apiCall(id); 8 | dispatch({ type: ACTION_TYPE, payload: data }); 9 | } catch (err) { 10 | throw new Error(err); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/58396438/apiCall.ts: -------------------------------------------------------------------------------- 1 | export const apiCall = async (id: string) => ({ data: id }); 2 | -------------------------------------------------------------------------------- /src/stackoverflow/58413956/anotherFile.ts: -------------------------------------------------------------------------------- 1 | export const outsideFunc = () => 1; 2 | -------------------------------------------------------------------------------- /src/stackoverflow/58413956/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { myFunc } from './'; 2 | import { outsideFunc } from './anotherFile'; 3 | 4 | jest.mock('./anotherFile.ts', () => ({ 5 | outsideFunc: jest.fn() 6 | })); 7 | 8 | describe('Testing myFunc', () => { 9 | it('Should call outsideFunc', () => { 10 | myFunc(); 11 | expect(jest.isMockFunction(outsideFunc)).toBeTruthy(); 12 | expect(outsideFunc).toHaveBeenCalled(); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/stackoverflow/58413956/index.ts: -------------------------------------------------------------------------------- 1 | import { outsideFunc } from './anotherFile'; 2 | 3 | export function myFunc() { 4 | outsideFunc(); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58445250/index.ts: -------------------------------------------------------------------------------- 1 | export default function download(blobUrl, fileName) { 2 | const link = document.createElement('a'); 3 | link.setAttribute('href', blobUrl); 4 | link.setAttribute('download', `${fileName}.pdf`); 5 | link.style.display = 'none'; 6 | 7 | document.body.appendChild(link); 8 | 9 | link.click(); 10 | 11 | document.body.removeChild(link); 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/58454044/index.ts: -------------------------------------------------------------------------------- 1 | (global as any).check = false; 2 | 3 | export const doStuff = () => 'doStuff'; 4 | export const doOtherStuff = () => 'doOtherStuff'; 5 | 6 | export function myFunction() { 7 | if ((global as any).check) { 8 | doStuff(); 9 | } else { 10 | doOtherStuff(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/58521281/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { someHelper } from './utils'; 3 | 4 | class SomeComponent extends Component { 5 | render() { 6 | return
    some component, {someHelper()}
    ; 7 | } 8 | } 9 | 10 | export default SomeComponent; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/58521281/utils.ts: -------------------------------------------------------------------------------- 1 | export const someHelper = () => 'return value'; 2 | -------------------------------------------------------------------------------- /src/stackoverflow/58524183/NotFound.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { useHistory } from 'react-router-dom'; 3 | 4 | const RouteNotFound = () => { 5 | const history = useHistory(); 6 | return ( 7 |
    8 |
    10 | ); 11 | }; 12 | 13 | export default RouteNotFound; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/58530865/a.spec.ts: -------------------------------------------------------------------------------- 1 | import * as a from './a'; 2 | 3 | describe('getData', () => { 4 | it('myFunc is called', async () => { 5 | const logSpy = jest.spyOn(console, 'log'); 6 | const myFuncMock = jest.spyOn(a, 'myFunc').mockResolvedValueOnce('mocked data'); 7 | await a.getData(); 8 | expect(myFuncMock).toHaveBeenCalled(); 9 | expect(logSpy).toBeCalledWith('mocked data'); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/stackoverflow/58530865/a.ts: -------------------------------------------------------------------------------- 1 | import { helper } from './utils'; 2 | 3 | export const myFunc = helper(async () => null, 1000); 4 | 5 | export const getData = () => { 6 | return myFunc().then(console.log); 7 | }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/58530865/utils.ts: -------------------------------------------------------------------------------- 1 | export const helper = (promiseFunc, time) => (...args) => 2 | Promise.race([promiseFunc(...args), new Promise((_, reject) => null)]); 3 | -------------------------------------------------------------------------------- /src/stackoverflow/58548563/index.ts: -------------------------------------------------------------------------------- 1 | import moment from 'moment-timezone'; 2 | 3 | export function main() { 4 | return moment.tz.guess(); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58561765/a.js: -------------------------------------------------------------------------------- 1 | const b = require('./b'); 2 | 3 | exports.main = function main() { 4 | console.log(b.method1()); 5 | console.log(b.method2()); 6 | console.log(b.method3()); 7 | }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/58561765/b.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | method1: function() { 3 | return 'method 1'; 4 | }, 5 | 6 | method2: function() { 7 | return 'method 2'; 8 | }, 9 | 10 | method3: function() { 11 | return 'method 3'; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/58562583/SignOutButton.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Firebase from './firebase'; 3 | 4 | console.log(Firebase.auth); 5 | console.log('should keep same reference to authObject:', Firebase.auth() === Firebase.auth()); 6 | 7 | const SignOutButton = () => ( 8 | 11 | ); 12 | 13 | export default SignOutButton; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/58562583/firebase.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | auth() { 3 | console.log('auth real implementation'); 4 | return this; 5 | }, 6 | async signOut() { 7 | console.log('signOut real implementation'); 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/58569731/auth.test.js: -------------------------------------------------------------------------------- 1 | const request = require('supertest'); 2 | const server = require('./server'); 3 | 4 | describe('auth middleware', () => { 5 | const exec = () => { 6 | return request(server) 7 | .post('/api/categories') 8 | .set('x-auth-token', 'token') 9 | .send({ name: 'category1' }); 10 | }; 11 | it('should return 200 if token is valid', async () => { 12 | const res = await exec(); 13 | expect(res.status).toBe(200); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/stackoverflow/58569731/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const bodyParser = require('body-parser'); 3 | const app = express(); 4 | const port = process.env.PORT || 3000; 5 | 6 | app.use(bodyParser.json()); 7 | app.post('/api/categories', (req, res) => { 8 | console.log(req.body); 9 | res.sendStatus(200); 10 | }); 11 | 12 | if (require.main === module) { 13 | app.listen(port, () => { 14 | console.info(`Listening on port ${port}...`); 15 | }); 16 | } 17 | 18 | module.exports = app; 19 | -------------------------------------------------------------------------------- /src/stackoverflow/58585527/window.setup.js: -------------------------------------------------------------------------------- 1 | window.scrollTo = jest.fn(); 2 | -------------------------------------------------------------------------------- /src/stackoverflow/58595518/index.ts: -------------------------------------------------------------------------------- 1 | export const add = () => async dispatch => { 2 | const res = await fetch('https://swapi.co/api/people/'); 3 | const res2 = await res.json(); 4 | const people = res2.results; 5 | 6 | return dispatch({ 7 | type: 'ADD', 8 | people 9 | }); 10 | }; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/58603653/index.ts: -------------------------------------------------------------------------------- 1 | export function main() { 2 | if (navigator.onLine) { 3 | console.log('online'); 4 | } else { 5 | console.log('offline'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/stackoverflow/58623194/dataService.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | retrieveData: async id => { 3 | return { code: 200, data: 'real data' }; 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58625148/index.spec.ts: -------------------------------------------------------------------------------- 1 | import generateFile from './'; 2 | import fsExtra from 'fs-extra'; 3 | 4 | const writeFileSpy = jest.spyOn(fsExtra, 'writeFile'); 5 | 6 | describe('writeFile', () => { 7 | test('it should check whether writeFile has been called', async () => { 8 | await generateFile('jest'); 9 | expect(writeFileSpy).toHaveBeenCalled(); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/stackoverflow/58625148/index.ts: -------------------------------------------------------------------------------- 1 | import { writeFile } from 'fs-extra'; 2 | import { resolve as pathResolve } from 'path'; 3 | 4 | export default async function generateFile(value): Promise { 5 | await writeSampleFile(value); 6 | } 7 | 8 | async function writeSampleFile(value: string): Promise { 9 | try { 10 | await writeFile(pathResolve(__dirname, './.tmp/somePath'), value, 'utf8'); 11 | } catch (err) {} 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/58644737/index.ts: -------------------------------------------------------------------------------- 1 | export class Component { 2 | object = { 3 | image: '' 4 | }; 5 | handleFileUpload(event) { 6 | let reader = new FileReader(); 7 | let file = event.target.files[0]; 8 | 9 | reader.readAsBinaryString(file); 10 | 11 | reader.onload = () => { 12 | let base64String = btoa(reader.result as string); 13 | this.object.image = base64String; 14 | }; 15 | 16 | return reader; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/stackoverflow/58648463/contants/svc.ts: -------------------------------------------------------------------------------- 1 | const getOrCreateStore = () => {}; 2 | 3 | class Svc { 4 | constructor(domain, getOrCreateStore) {} 5 | 6 | public async getMe() { 7 | return { data: { mfa_enabled: true } }; 8 | } 9 | } 10 | 11 | export default new Svc(process.env.AUTH_API_DOMAIN, getOrCreateStore()); 12 | -------------------------------------------------------------------------------- /src/stackoverflow/58648691/index.js: -------------------------------------------------------------------------------- 1 | const fetch = require('node-fetch'); 2 | 3 | module.exports = { 4 | async doSomething(url, token) { 5 | return fetch(url).then(res => res.json()); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/58651192/index.ts: -------------------------------------------------------------------------------- 1 | export async function getPrice(page, url) { 2 | const priceSelector = '#price'; 3 | if (await page.$(priceSelector)) { 4 | return page.$eval(priceSelector, evalCallback); 5 | } 6 | return null; 7 | } 8 | 9 | export const evalCallback = elem => elem.innerText; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/58652312/index.spec.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { shallow } from 'enzyme'; 3 | import MyClass from './'; 4 | 5 | describe('MyClass', () => { 6 | test('should handle mousedown event', () => { 7 | const wrapper = shallow(); 8 | const onMouseDownHandlerSpy = jest.spyOn(MyClass.prototype, 'onMouseDownHandler'); 9 | wrapper.find('div').simulate('mouseDown'); 10 | expect(onMouseDownHandlerSpy).toBeCalled(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/58663681/api.tests.js: -------------------------------------------------------------------------------- 1 | test('t1', () => { 2 | expect(1).toBe(1); 3 | }); 4 | -------------------------------------------------------------------------------- /src/stackoverflow/58674975/index.spec.ts: -------------------------------------------------------------------------------- 1 | import scrape from './scrape'; 2 | import main from './'; 3 | 4 | jest.mock('./scrape.ts', () => jest.fn().mockResolvedValueOnce('fake data')); 5 | 6 | describe('main', () => { 7 | test('should return data', async () => { 8 | const actualValue = await main; 9 | expect(actualValue).toBe('fake data'); 10 | expect(scrape).toBeCalledTimes(1); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/58674975/index.ts: -------------------------------------------------------------------------------- 1 | import scrape from './scrape'; 2 | 3 | const main = (async () => { 4 | return await scrape(); 5 | })(); 6 | 7 | export default main; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/58674975/scrape.ts: -------------------------------------------------------------------------------- 1 | export default async function scrape() { 2 | return 'real data'; 3 | } 4 | -------------------------------------------------------------------------------- /src/stackoverflow/58692161/controller.js: -------------------------------------------------------------------------------- 1 | const apiModel = require('./api'); 2 | 3 | module.exports.updateProductStatus = async (req, res, next) => { 4 | let result = await apiModel.updateProductStatus(req.body); 5 | if (result.affectedRows > 0) { 6 | res.send({ 7 | status: 'success', 8 | message: 'product status updated.' 9 | }); 10 | } else { 11 | res.send({ 12 | status: 'error', 13 | message: 'failed to update product status.' 14 | }); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /src/stackoverflow/58692161/db.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | async query() { 3 | return 'real query'; 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58696477/index.js: -------------------------------------------------------------------------------- 1 | import $ from 'jquery'; 2 | 3 | function factBox() { 4 | console.log('GHEje fwe'); 5 | $('body').css('background-color', 'red'); 6 | } 7 | 8 | function sum(a, b) { 9 | console.log('SUMMM'); 10 | return a + b; 11 | } 12 | 13 | export { factBox, sum }; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/58696477/index.spec.js: -------------------------------------------------------------------------------- 1 | import { sum } from '.'; 2 | 3 | test('add 1 + 2 to equal 3', () => { 4 | expect(sum(1, 2)).toBe(3); 5 | }); 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58710736/index.js: -------------------------------------------------------------------------------- 1 | export class SomeClass { 2 | editableData = { 3 | jest: [] 4 | }; 5 | $uuid = { 6 | v1() { 7 | return 'real uuid'; 8 | } 9 | }; 10 | addDataItem(key) { 11 | const basicDataItem = { 12 | id: this.$uuid.v1(), 13 | units: '', 14 | price: '', 15 | label: '' 16 | }; 17 | 18 | this.editableData[key].push(basicDataItem); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/stackoverflow/58727351/ddb.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | async scan() { 3 | return 'real scan'; 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58727351/tools.js: -------------------------------------------------------------------------------- 1 | const ddb = require('./ddb'); 2 | 3 | const table = process.env.TableName; 4 | 5 | module.exports.mailExist = async email => { 6 | if (!email) { 7 | throw new Error('Missing parameters'); 8 | } 9 | return await ddb.scan({ 10 | TableName: table, 11 | FilterExpression: 'email = :email', 12 | ExpressionAttributeValues: { 13 | ':email': email 14 | }, 15 | ProjectionExpression: ['uid'] 16 | }); 17 | }; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/58741410/AuthService.js: -------------------------------------------------------------------------------- 1 | export default class AuthService { 2 | constructor() { 3 | this.fetch = this.fetch.bind(this); 4 | } 5 | fetch(url) { 6 | return fetch(url).then(res => { 7 | return res.json(); 8 | }); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/stackoverflow/58741410/Tester.jsx: -------------------------------------------------------------------------------- 1 | import AuthService from './AuthService'; 2 | import React, { useState, useEffect } from 'react'; 3 | 4 | export default () => { 5 | const Auth = new AuthService(); 6 | const [thing, setThing] = useState(''); 7 | useEffect(() => { 8 | console.count('useEffect'); 9 | Auth.fetch('url').then(data => { 10 | setThing(data); 11 | }); 12 | }, []); 13 | return

    {thing}

    ; 14 | }; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/58746881/filters-state.helper.ts: -------------------------------------------------------------------------------- 1 | type FiltersState = any; 2 | 3 | export const FiltersStateHelper = { 4 | toggleFilters: (state: T): T => ({ 5 | ...state, 6 | isOpen: !state.isOpen 7 | }) 8 | }; 9 | -------------------------------------------------------------------------------- /src/stackoverflow/58746881/search-view-state.helper.ts: -------------------------------------------------------------------------------- 1 | import { FiltersStateHelper } from './filters-state.helper'; 2 | 3 | type SearchViewState = any; 4 | 5 | export const SearchViewStateHelper = { 6 | toggleFilters: (state: T): T => ({ 7 | ...state, 8 | filters: FiltersStateHelper.toggleFilters(state.filters) 9 | }) 10 | // ... more methods 11 | }; 12 | -------------------------------------------------------------------------------- /src/stackoverflow/58758771/v1/constants.ts: -------------------------------------------------------------------------------- 1 | export function get() { 2 | return { 3 | build: 'dist', 4 | action: { 5 | pusher: { 6 | name: 'montezuma', 7 | email: 'best@cat' 8 | }, 9 | gitHubToken: 'exists' 10 | } 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/58758771/v1/index.ts: -------------------------------------------------------------------------------- 1 | import { get } from './constants'; 2 | 3 | export async function init() { 4 | return get(); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58758771/v2/constants.ts: -------------------------------------------------------------------------------- 1 | export const constants = { 2 | build: 'dist', 3 | action: { 4 | pusher: { 5 | name: 'montezuma', 6 | email: 'best@cat' 7 | }, 8 | gitHubToken: 'exists' 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/58758771/v2/index.ts: -------------------------------------------------------------------------------- 1 | import { constants } from './constants'; 2 | 3 | export async function init() { 4 | return constants; 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58786973/index.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect } from 'react'; 2 | import { withRouter } from 'react-router-dom'; 3 | 4 | type IRouterResetScroll = any; 5 | 6 | export const ScrollToTop = ({ history }: IRouterResetScroll) => { 7 | useEffect(() => { 8 | const unListen = history.listen(() => { 9 | window.scrollTo(0, 0); 10 | }); 11 | return () => { 12 | unListen(); 13 | }; 14 | }, []); 15 | 16 | return null; 17 | }; 18 | 19 | export default withRouter(ScrollToTop); 20 | -------------------------------------------------------------------------------- /src/stackoverflow/58808783/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const styles = { 4 | sendEmail: 'sendEmail' 5 | }; 6 | 7 | export const SendProjectManagerEmail = ({ sendEmail }) => { 8 | return ( 9 | 12 | ); 13 | }; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/58810079/index.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | 3 | export const viewText = () => { 4 | fs.readFile('poem.txt', 'utf8', (err, data) => { 5 | if (err) throw err; 6 | console.log(data); 7 | }); 8 | }; 9 | -------------------------------------------------------------------------------- /src/stackoverflow/58815471/index.ts: -------------------------------------------------------------------------------- 1 | export class MyComponent { 2 | private myService; 3 | constructor(myService) { 4 | this.myService = myService; 5 | } 6 | public testFunction(): void { 7 | this.myService.returnMyObservable.subscribe(value => this.doAThing(value)); 8 | } 9 | public doAThing(value) {} 10 | } 11 | -------------------------------------------------------------------------------- /src/stackoverflow/58820204/index.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class AutoComplete extends Component { 4 | render() { 5 | return ( 6 |
    7 |
      8 | {this.props.match.map(item => { 9 | return
    • {item.name}
    • ; 10 | })} 11 |
    12 |
    13 | ); 14 | } 15 | } 16 | 17 | export default AutoComplete; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/58826185/__snapshots__/index.spec.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Component should handle change event 1`] = ` 4 | 5 | 6 |
    7 | 10 | 13 | 14 |
    15 |
    16 |
    17 | `; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/58826185/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | 3 | const View = ({ children }) =>
    {children}
    ; 4 | const CustomComponent = ({ onChange }) => onChange(e.target.value)}>; 5 | 6 | export const Component: React.FC<{}> = () => { 7 | const [value, setState] = useState(''); 8 | console.log(value); 9 | return ( 10 | 11 | setState(val)} /> 12 | 13 | ); 14 | }; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/58842143/api.js: -------------------------------------------------------------------------------- 1 | const csv = require('csvtojson'); 2 | const request = require('request'); 3 | 4 | export const getApiData = url => { 5 | return csv() 6 | .fromStream(request.get(url)) 7 | .subscribe(json => json); 8 | }; 9 | -------------------------------------------------------------------------------- /src/stackoverflow/58859904/notifications.ts: -------------------------------------------------------------------------------- 1 | import firebase from 'react-native-firebase'; 2 | 3 | export async function subscribeToTopic(topic) { 4 | await firebase.messaging().subscribeToTopic(topic); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/58877501/index.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class SomeCompoennt extends Component { 4 | constructor(props) { 5 | super(props); 6 | this.state = { authUrl: '' }; 7 | this.props.getPaypalAuthUrl().then((result) => { 8 | this.setState({ authUrl: result }); 9 | }); 10 | } 11 | render() { 12 | return
    some component
    ; 13 | } 14 | } 15 | 16 | export default SomeCompoennt; 17 | -------------------------------------------------------------------------------- /src/stackoverflow/58948797/index.ts: -------------------------------------------------------------------------------- 1 | export function main() { 2 | const RedisEnableCache = process.env.REDIS_ENABLE_CACHE || false; 3 | if (RedisEnableCache === "true") { 4 | console.log("enable redis cache"); 5 | } else { 6 | console.log("disable redis cache"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/stackoverflow/59024742/customer.ts: -------------------------------------------------------------------------------- 1 | export const saveDetails = () => { 2 | console.log("real save details"); 3 | }; 4 | export const loadDetails = () => { 5 | console.log("real load details"); 6 | }; 7 | -------------------------------------------------------------------------------- /src/stackoverflow/59024742/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { main } from "./"; 2 | import { saveDetails, loadDetails } from "./customer"; 3 | 4 | jest.mock("./customer.ts", () => { 5 | return { 6 | saveDetails: jest.fn(), 7 | loadDetails: jest.fn() 8 | }; 9 | }); 10 | 11 | describe("main", () => { 12 | it("should mock correctly", () => { 13 | main(); 14 | expect(saveDetails).toBeCalledTimes(1); 15 | expect(loadDetails).toBeCalledTimes(1); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/stackoverflow/59024742/index.ts: -------------------------------------------------------------------------------- 1 | import { saveDetails, loadDetails } from "./customer"; 2 | 3 | export function main() { 4 | saveDetails(); 5 | loadDetails(); 6 | } 7 | -------------------------------------------------------------------------------- /src/stackoverflow/59027031/unzipper.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | Extract(opts) { 3 | // real implementation 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/59035729/UserService.ts: -------------------------------------------------------------------------------- 1 | export const create = async body => { 2 | console.log("... save to db ..."); 3 | }; 4 | 5 | export const getById = async id => { 6 | console.log("... returns user from database ..."); 7 | }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/59035729/auth.ts: -------------------------------------------------------------------------------- 1 | import * as UserService from "./UserService"; 2 | 3 | export async function auth(userService: typeof UserService) { 4 | await userService.getById("1"); 5 | await userService.create({ name: "jest" }); 6 | } 7 | -------------------------------------------------------------------------------- /src/stackoverflow/59057693/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { isElementInViewport } from "./"; 2 | 3 | describe("isElementInViewport", () => { 4 | it("t-1", () => { 5 | const mEl = { 6 | getBoundingClientRect: jest 7 | .fn() 8 | .mockReturnValueOnce({ top: 0, left: 0, bottom: 0, right: 0 }) 9 | }; 10 | const actual = isElementInViewport(mEl); 11 | expect(actual).toBeTruthy(); 12 | expect(mEl.getBoundingClientRect).toBeCalledTimes(1); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/stackoverflow/59057693/index.ts: -------------------------------------------------------------------------------- 1 | export function isElementInViewport(ele) { 2 | const rect = ele.getBoundingClientRect(); 3 | const InViewPort = 4 | rect.top >= 0 && rect.left >= 0 && rect.bottom <= 0 && rect.right <= 0; 5 | return InViewPort; 6 | } 7 | -------------------------------------------------------------------------------- /src/stackoverflow/59062023/index.ts: -------------------------------------------------------------------------------- 1 | export function main() { 2 | const blob = new Blob(["testing"], { type: "application/pdf" }); 3 | console.log(blob); 4 | } 5 | -------------------------------------------------------------------------------- /src/stackoverflow/59068158/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const bodyParser = require('body-parser'); 3 | const app = express(); 4 | 5 | app.use(bodyParser.text()); 6 | app.post('/myservice/v1/api/user', (req, res) => { 7 | console.log(req.body); 8 | res.status(201).send('user created successfully.'); 9 | }); 10 | 11 | module.exports = app; 12 | -------------------------------------------------------------------------------- /src/stackoverflow/59084313/index.ts: -------------------------------------------------------------------------------- 1 | export class SomeClass { 2 | ws; 3 | run() { 4 | const WebSocket = require("ws"); 5 | const url = ""; 6 | this.ws = new WebSocket(url); 7 | return new Promise((resolve, reject) => { 8 | this.ws.on("open", () => { 9 | resolve(); 10 | }); 11 | this.ws.on("error", err => { 12 | reject(err); 13 | }); 14 | }); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/stackoverflow/59090082/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const request = require('request-promise'); 3 | const app = express(); 4 | 5 | app.post('/abc', async (req, res) => { 6 | const url = req.protocol + '://' + req.get('host'); 7 | const rval = await request.post(`${url}/def`); 8 | res.send(rval); 9 | }); 10 | app.post('/def', (req, res) => { 11 | res.send('def'); 12 | }); 13 | 14 | module.exports = app; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/59090082/server.test.js: -------------------------------------------------------------------------------- 1 | const supertest = require('supertest'); 2 | const app = require('./server'); 3 | 4 | describe('server', () => { 5 | it('should pass', (done) => { 6 | supertest(app) 7 | .post('/abc') 8 | .expect(200) 9 | .end((err, res) => { 10 | if (err) throw err; 11 | expect(res.text).toBe('def'); 12 | done(); 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/stackoverflow/59090082/start.js: -------------------------------------------------------------------------------- 1 | const app = require('./server.js'); 2 | const s = app.listen(3000, () => { 3 | console.log(`HTTP server is listening on http://localhost:${s.address().port}`); 4 | }); 5 | -------------------------------------------------------------------------------- /src/stackoverflow/59146770/index.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import Cookies from "universal-cookie"; 3 | import axios from "axios"; 4 | 5 | const cookies = new Cookies(); 6 | 7 | export class MyComponent extends React.Component { 8 | componentDidMount() { 9 | axios.defaults.headers.common.Authorization = cookies.get("token").value; //12492525 10 | console.log(axios.defaults.headers.common.Authorization); 11 | } 12 | render() { 13 | return null; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/stackoverflow/59150545/third-party.js: -------------------------------------------------------------------------------- 1 | export default function ThirdParty() {} 2 | 3 | ThirdParty.prototype.createThing = function() { 4 | console.log("real create thing"); 5 | return this; 6 | }; 7 | 8 | ThirdParty.prototype.nestedFunction = function(arg, cb) { 9 | console.log("real nested function"); 10 | }; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/59163345/types.ts: -------------------------------------------------------------------------------- 1 | export enum AWS_DEFAULTS { 2 | PROFILE = "PROFILE" 3 | } 4 | -------------------------------------------------------------------------------- /src/stackoverflow/59168766/index.js: -------------------------------------------------------------------------------- 1 | const plus1 = x => x + 1; 2 | 3 | const plus2 = x => x + 2; 4 | 5 | const returnPlus1OrPlus2 = (number, code) => 6 | code === 1 ? exports.plus1(number * 3) : exports.plus2(number); 7 | 8 | exports.plus1 = plus1; 9 | exports.plus2 = plus2; 10 | export default returnPlus1OrPlus2; 11 | -------------------------------------------------------------------------------- /src/stackoverflow/59169619/index.spec.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import App from "./"; 3 | import { mount } from "enzyme"; 4 | 5 | describe("App", () => { 6 | it("should pass", () => { 7 | const wrapper = mount(); 8 | expect(wrapper).toMatchInlineSnapshot(` 9 | 10 | 14 | Google 15 | 16 | 17 | `); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /src/stackoverflow/59187875/asmConfigService.ts: -------------------------------------------------------------------------------- 1 | export class ConfigService { 2 | public static async getConfig(token) { 3 | return { 4 | ThisSecretString: JSON.stringify({ 5 | ThisclientId: 'real id', 6 | ThisclientSecret: 'real secret', 7 | }), 8 | }; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/stackoverflow/59197574/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useReducer, useEffect } from 'react'; 2 | import { listReducer, fetchList } from './reducer'; 3 | 4 | export const Posts = () => { 5 | const [list, dispatch] = useReducer(listReducer, []); 6 | 7 | useEffect(() => { 8 | fetchList(dispatch); 9 | }, []); 10 | 11 | return ( 12 |
      13 | {list.map((el) => ( 14 |
    • {el.title}
    • 15 | ))} 16 |
    17 | ); 18 | }; 19 | -------------------------------------------------------------------------------- /src/stackoverflow/59198002/index.ts: -------------------------------------------------------------------------------- 1 | export class AgeVerification { 2 | public onDeclineCallback = () => { 3 | console.log('boom ' + document.referrer); 4 | 5 | if (document.referrer === '') { 6 | console.log('redirect to our age policy page'); 7 | } else { 8 | history.back(); 9 | } 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /src/stackoverflow/59207566/ModelUtility.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | buildSearchParameter(...args) { 3 | return 'real search parameter'; 4 | }, 5 | isUnknownFields(...args) { 6 | return true; 7 | }, 8 | }; 9 | -------------------------------------------------------------------------------- /src/stackoverflow/59208419/App.js: -------------------------------------------------------------------------------- 1 | import * as utils from './Utils'; 2 | 3 | export function bootstrap() { 4 | return utils.add(); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/59208419/Utils.js: -------------------------------------------------------------------------------- 1 | export const add = () => { 2 | const x = 1; 3 | return x; 4 | }; 5 | -------------------------------------------------------------------------------- /src/stackoverflow/59233898/index.js: -------------------------------------------------------------------------------- 1 | import decode from 'jwt-decode'; 2 | 3 | export const checkAuth = () => { 4 | const token = localStorage.getItem('token'); 5 | if (!token) { 6 | return false; 7 | } 8 | 9 | try { 10 | const { exp } = decode(token); 11 | if (exp < new Date().getTime() / 1000) { 12 | console.log(123); 13 | return false; 14 | } 15 | } catch (e) { 16 | console.log(e); 17 | return false; 18 | } 19 | 20 | return true; 21 | }; 22 | -------------------------------------------------------------------------------- /src/stackoverflow/59235639/config/IDBConnection.ts: -------------------------------------------------------------------------------- 1 | export interface IDBConnection {} 2 | -------------------------------------------------------------------------------- /src/stackoverflow/59241777/api/getProducts.ts: -------------------------------------------------------------------------------- 1 | export async function getProducts(url) { 2 | return { result: [] }; 3 | } 4 | -------------------------------------------------------------------------------- /src/stackoverflow/59250480/pdf.js: -------------------------------------------------------------------------------- 1 | const PdfPrinter = require('pdfmake'); 2 | // const fonts = require('./../shared/fonts') 3 | const fonts = {}; 4 | 5 | const printer = new PdfPrinter(fonts); 6 | 7 | const intiateDocCreation = (docDefinition) => printer.createPdfKitDocument(docDefinition); 8 | 9 | const finishDocCreation = (pdfDoc, pdfStream) => { 10 | pdfDoc.pipe(pdfStream); 11 | pdfDoc.end(); 12 | }; 13 | 14 | module.exports = { 15 | intiateDocCreation, 16 | finishDocCreation, 17 | }; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/59261385/a.js: -------------------------------------------------------------------------------- 1 | const request = require('request-promise'); 2 | 3 | module.exports = async () => { 4 | var options = { 5 | uri: 'fsdsfd', 6 | headers: { 7 | 'content-type': 'application/json', 8 | }, 9 | body: { 10 | A: 'A', 11 | B: 'B', 12 | }, 13 | json: true, 14 | }; 15 | 16 | try { 17 | const selectResult = await request.post(options); 18 | return selectResult; 19 | } catch (err) { 20 | return err; 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /src/stackoverflow/59266532/ScriptTag.test.ts: -------------------------------------------------------------------------------- 1 | import { ScriptTag } from './ScriptTag'; 2 | 3 | describe('ScriptTag', () => { 4 | it('should pass', () => { 5 | jest.spyOn(ScriptTag.prototype, 'getFileName').mockImplementation(() => 'scriptTag.js'); 6 | const scriptTag: ScriptTag = new ScriptTag('subdomain.shopify.com', 'generalTokenValue', '../path/to/file.js'); 7 | expect(scriptTag.localFileName).toEqual('scriptTag.js'); 8 | expect(scriptTag.getFileName).toBeCalled(); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/stackoverflow/59281612/index.spec.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { TestContainer } from './'; 3 | import { shallow } from 'enzyme'; 4 | 5 | describe('TestContainer', () => { 6 | it('should pass', () => { 7 | const wrapper = shallow(); 8 | const instance = wrapper.instance(); 9 | expect(wrapper.exists()).toBeTruthy(); 10 | expect(instance['myValue']).toBe(5); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/59281612/index.tsx: -------------------------------------------------------------------------------- 1 | import { Component } from 'react'; 2 | 3 | export class TestContainer extends Component { 4 | public myValue = -1; 5 | constructor(props) { 6 | super(props); 7 | this.myValue = 5; 8 | } 9 | public render() { 10 | return null; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/59298693/index.ts: -------------------------------------------------------------------------------- 1 | import cloneDeep from 'lodash/cloneDeep'; 2 | 3 | export class SomeClass { 4 | public static transformBoardBasicInfo(rawBoard: any): any { 5 | const clonedBoard: any = cloneDeep(rawBoard) as any; 6 | clonedBoard.info = this.getInfo(rawBoard); 7 | return clonedBoard; 8 | } 9 | 10 | public static getInfo(board) { 11 | return ''; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/stackoverflow/59311270/functions.ts: -------------------------------------------------------------------------------- 1 | export interface IEventData {} 2 | 3 | export function processEvent() { 4 | return (event: IEventData) => { 5 | const eventType = exports.getEventType(event); 6 | return eventType; 7 | }; 8 | } 9 | 10 | function getEventType(event: IEventData): string { 11 | return ''; 12 | } 13 | 14 | exports.getEventType = getEventType; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/59319610/main.test.ts: -------------------------------------------------------------------------------- 1 | import { main } from './main'; 2 | 3 | describe('main', () => { 4 | it('should pass', () => { 5 | const original = process.env.MOCK_MODE; 6 | process.env.MOCK_MODE = 'true'; 7 | const actual = main(); 8 | expect(actual).toBe('true'); 9 | process.env.MOCK_MODE = original; 10 | }); 11 | it('should restore MOCK_MODE', () => { 12 | expect(process.env.MOCK_MODE).toBe('undefined'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/stackoverflow/59319610/main.ts: -------------------------------------------------------------------------------- 1 | export function main() { 2 | const mockMode = process.env.MOCK_MODE; 3 | return mockMode; 4 | } 5 | -------------------------------------------------------------------------------- /src/stackoverflow/59330476/index.ts: -------------------------------------------------------------------------------- 1 | export class SomeClass { 2 | INCREMENT = 1; 3 | MIN_SCALE = 2; 4 | public zoomOut(this: any): void { 5 | const scaleVal = this.getFloorVar() || this.INCREMENT || this.MIN_SCALE; 6 | this.updateZoom(scaleVal); 7 | } 8 | 9 | public getFloorVar() { 10 | return 0; 11 | } 12 | 13 | public updateZoom(scaleVal) { 14 | console.log(scaleVal); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/stackoverflow/59352068/testClass.js: -------------------------------------------------------------------------------- 1 | const loaders = { 2 | model: (arg1) => { 3 | // do something to return models data 4 | console.log('do something to return models data'); 5 | }, 6 | events: (arg2) => { 7 | // do something to return events data 8 | }, 9 | }; 10 | 11 | export default class TestClass { 12 | constructor(config) { 13 | this.loader = loaders[config.type]; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/stackoverflow/59366107/Book-logger.ts: -------------------------------------------------------------------------------- 1 | export default class BookLogger { 2 | public static LOG_LEVEL = { 3 | INFO: 'INFO', 4 | }; 5 | public static getLogger(name, level) { 6 | return { 7 | error: (message) => { 8 | console.error(message); 9 | }, 10 | }; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/59366107/main.ts: -------------------------------------------------------------------------------- 1 | import BookLogger from './Book-logger'; 2 | const logger = BookLogger.getLogger('Book-service', BookLogger.LOG_LEVEL.INFO); 3 | 4 | export function main() { 5 | const error = new Error('Internal server error'); 6 | logger.error(`Failed to get All Books in given category ${error}`); 7 | } 8 | -------------------------------------------------------------------------------- /src/stackoverflow/59371450/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { authorizer } from './'; 2 | 3 | describe('authorizer', () => { 4 | it('should authorize', () => { 5 | const event = 'message'; 6 | const mockCallback = jest.fn().mockReturnValue('ok'); 7 | authorizer(event, null, mockCallback); 8 | expect(mockCallback).toHaveBeenCalled(); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/stackoverflow/59371450/index.ts: -------------------------------------------------------------------------------- 1 | export const authorizer = (event, context, callback) => { 2 | const token = event.authorizationToken; 3 | const policyDocument = {}; 4 | try { 5 | callback(null, policyDocument); 6 | } catch (e) { 7 | callback('Unauthorized'); 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/59423508/main.js: -------------------------------------------------------------------------------- 1 | export function main() { 2 | const selectElement = document.querySelector('#selectbox'); 3 | return selectElement; 4 | } 5 | -------------------------------------------------------------------------------- /src/stackoverflow/59423508/main.test.js: -------------------------------------------------------------------------------- 1 | import { main } from './main'; 2 | 3 | describe('59423508', () => { 4 | it('should pass', () => { 5 | const mElement = {}; 6 | document.querySelector = jest.fn().mockReturnValueOnce(mElement); 7 | const actual = main(); 8 | expect(actual).toEqual(mElement); 9 | expect(document.querySelector).toBeCalledWith('#selectbox'); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/stackoverflow/59426030/app.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const tokenStore = require('./token-store'); 3 | 4 | const app = express(); 5 | 6 | const someHandler = async (req, res) => { 7 | const token = await tokenStore.getToken(); 8 | res.send(token); 9 | }; 10 | 11 | app.get('/api/users', someHandler); 12 | 13 | module.exports = app; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/59426030/token-store.js: -------------------------------------------------------------------------------- 1 | async function getToken() { 2 | return 'real token'; 3 | } 4 | 5 | module.exports = { 6 | getToken, 7 | }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/59430114/index.ts: -------------------------------------------------------------------------------- 1 | function trimLeft(str: string): string { 2 | if (String.prototype.trimLeft) { 3 | return str.trimLeft(); 4 | } else { 5 | return str.replace(/^[\s\uFEFF\xA0]+/, ''); 6 | } 7 | } 8 | 9 | function trimRight(str: string): string { 10 | if (String.prototype.trimRight) { 11 | return str.trimRight(); 12 | } else { 13 | return str.replace(/[\s\uFEFF\xA0]+$/, ''); 14 | } 15 | } 16 | 17 | export { trimLeft, trimRight }; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/59431651/_validation/report.js: -------------------------------------------------------------------------------- 1 | const validationSchema = { 2 | validate(body) { 3 | return body; 4 | }, 5 | }; 6 | 7 | export default validationSchema; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/59431651/ctrl.js: -------------------------------------------------------------------------------- 1 | import validationSchema from './_validation/report'; 2 | import reportModel from './models/report'; 3 | 4 | const ctrl = {}; 5 | 6 | ctrl.addReport = async (req, res) => { 7 | const { body } = req; 8 | const validatedData = await validationSchema.validate(body); 9 | const report = await reportModel(req.dbConnection).addReport(validatedData); 10 | }; 11 | 12 | module.exports = ctrl; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/59431651/models/report.js: -------------------------------------------------------------------------------- 1 | function reportModel(connection) { 2 | return { 3 | async addReport(data) { 4 | console.log('addReport'); 5 | }, 6 | }; 7 | } 8 | export default reportModel; 9 | -------------------------------------------------------------------------------- /src/stackoverflow/59448015/useResponsive.ts: -------------------------------------------------------------------------------- 1 | export default function useResponsive(options: Array<[string, T]>) { 2 | for (const [mediaQuery, result] of options) { 3 | if (window.matchMedia(mediaQuery).matches) { 4 | return result; 5 | } 6 | } 7 | 8 | return undefined; 9 | } 10 | -------------------------------------------------------------------------------- /src/stackoverflow/59455504/index.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class App extends Component { 4 | mailReference = React.createRef(); 5 | handlingEmailBlur = (events) => { 6 | this.mailReference.current.validate(events.target.value); 7 | }; 8 | 9 | render() { 10 | return ( 11 |
    12 | some component 13 |
    14 | ); 15 | } 16 | } 17 | 18 | export default App; 19 | -------------------------------------------------------------------------------- /src/stackoverflow/59459690/validator.js: -------------------------------------------------------------------------------- 1 | const validator = { 2 | validate: async (fields) => { 3 | console.log('validate fields'); 4 | }, 5 | }; 6 | 7 | module.exports = validator; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/59466379/sample.ts: -------------------------------------------------------------------------------- 1 | export class Sample { 2 | update(): void { 3 | this.update1(); 4 | this.update2(); 5 | } 6 | 7 | protected update1(): void { 8 | console.log('hai'); 9 | } 10 | 11 | protected update2(): void { 12 | console.log('hello'); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/stackoverflow/59475724/index.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | 3 | const Counter = () => { 4 | const [counter, setCounter] = useState(0); 5 | const incCounter = () => { 6 | setCounter(counter + 1); 7 | }; 8 | return ( 9 | <> 10 |

    Counter value is: {counter}

    11 | 14 | 15 | ); 16 | }; 17 | export default Counter; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/59481051/index.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export default class Btn extends React.Component { 4 | constructor(props) { 5 | super(props); 6 | this.toggleClick = this.toggleClick.bind(this); 7 | } 8 | 9 | toggleClick() { 10 | const { onClick } = this.props; 11 | onClick(); 12 | } 13 | 14 | render() { 15 | return ( 16 | 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/stackoverflow/59494359/index.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class SomeComponent extends Component { 4 | onSubmit = (e) => { 5 | e.preventDefault(); 6 | window.scrollTo({ top: 0 }); 7 | }; 8 | 9 | render() { 10 | return ( 11 |
    12 |
    13 |
    14 | ); 15 | } 16 | } 17 | 18 | export default SomeComponent; 19 | -------------------------------------------------------------------------------- /src/stackoverflow/59495121/getAnswers.js: -------------------------------------------------------------------------------- 1 | const inquirer = require('inquirer'); 2 | 3 | const getAnswers = async (request) => { 4 | const answer = await inquirer.prompt(request); 5 | return answer; 6 | }; 7 | 8 | module.exports = getAnswers; 9 | -------------------------------------------------------------------------------- /src/stackoverflow/59508494/service.js: -------------------------------------------------------------------------------- 1 | export function calcu(id, code) { 2 | return id + code; 3 | } 4 | -------------------------------------------------------------------------------- /src/stackoverflow/59515767/index.js: -------------------------------------------------------------------------------- 1 | import { startOfToday } from 'date-fns'; 2 | 3 | export default function main() { 4 | return startOfToday(); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/59515767/index.spec.js: -------------------------------------------------------------------------------- 1 | import main from './'; 2 | import { startOfToday } from 'date-fns'; 3 | 4 | jest.mock('date-fns', () => ({ startOfToday: jest.fn() })); 5 | 6 | describe('59515767', () => { 7 | afterEach(() => { 8 | jest.resetAllMocks(); 9 | }); 10 | it('should pass', () => { 11 | startOfToday.mockReturnValueOnce('Tues Dec 28 2019 00:00:00 GMT+0000'); 12 | const actual = main(); 13 | expect(actual).toBe('Tues Dec 28 2019 00:00:00 GMT+0000'); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/stackoverflow/59520741/main.test.js: -------------------------------------------------------------------------------- 1 | const tests = require('./test_file.js'); 2 | console.log('000'); 3 | 4 | describe.skip('test block 1', function() { 5 | let input; 6 | console.log('111'); 7 | beforeAll(() => { 8 | console.log('222'); 9 | input = true; 10 | }); 11 | tests(input); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/59520741/test_file.js: -------------------------------------------------------------------------------- 1 | console.log('333'); 2 | function tests(input) { 3 | console.log('444'); 4 | it('should pass', function() { 5 | console.log('555'); 6 | expect(input).toBeTruthy(); 7 | }); 8 | } 9 | module.exports = tests; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/59540432/handler.js: -------------------------------------------------------------------------------- 1 | export function success(data) {} 2 | export function failure(data) {} 3 | -------------------------------------------------------------------------------- /src/stackoverflow/59581721/index.ts: -------------------------------------------------------------------------------- 1 | const readFileAsync = (file, use = false) => 2 | new Promise((resolve, reject) => { 3 | const reader = new FileReader(); 4 | reader.onload = () => { 5 | resolve(reader.result); 6 | }; 7 | reader.onerror = reject; 8 | if (use) reader.readAsDataURL(file); 9 | else reader.readAsArrayBuffer(file); 10 | (readFileAsync as any)._reader = reader; 11 | }); 12 | 13 | export default readFileAsync; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/59586141/api.js: -------------------------------------------------------------------------------- 1 | export function fetchData() { 2 | // real implementation 3 | } 4 | -------------------------------------------------------------------------------- /src/stackoverflow/59591410/apiservice.js: -------------------------------------------------------------------------------- 1 | const apiService = { 2 | async getAllGroups() { 3 | return []; 4 | }, 5 | }; 6 | 7 | export default apiService; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/59591410/group.js: -------------------------------------------------------------------------------- 1 | import apiService from './apiservice'; 2 | 3 | class Group { 4 | groups = []; 5 | getAllGroups() { 6 | return apiService 7 | .getAllGroups() 8 | .then((data) => { 9 | this.groups = data; 10 | }) 11 | .catch((error) => { 12 | console.log(error.response.data.message); 13 | }); 14 | } 15 | } 16 | 17 | export default Group; 18 | -------------------------------------------------------------------------------- /src/stackoverflow/59627009/adc.service.ts: -------------------------------------------------------------------------------- 1 | export default class ADCServices { 2 | public static async getUserInfo() { 3 | return { 4 | session: { 5 | tammUserInfo: { 6 | Type: 'real type', 7 | }, 8 | }, 9 | }; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/stackoverflow/59627009/work.ts: -------------------------------------------------------------------------------- 1 | import { SOP3loginConfig, IVariables } from './sop3login'; 2 | 3 | const start = async (props: IVariables) => { 4 | if (props.user) { 5 | if (await SOP3loginConfig(props).isSOP3()) { 6 | props.history.push('/adc/card-renewal/customs'); 7 | } 8 | } else { 9 | props.history.push(SOP3loginConfig(props).loginLink); 10 | } 11 | }; 12 | 13 | export { start }; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/59715038/templateService.ts: -------------------------------------------------------------------------------- 1 | export const getTemplate = async () => { 2 | return { data: 'real data' }; 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/59731700/main.ts: -------------------------------------------------------------------------------- 1 | import Busboy from 'busboy'; 2 | 3 | export function main() { 4 | const busboy = new Busboy({}); 5 | busboy.on('file', (fieldname, file, filename, encoding, mimetype) => { 6 | console.log( 7 | 'File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype, 8 | ); 9 | }); 10 | } 11 | -------------------------------------------------------------------------------- /src/stackoverflow/59735993/__mocks__/api_59735993.js: -------------------------------------------------------------------------------- 1 | const data = { 2 | results: [ 3 | { 4 | name: { 5 | first: 'sparky', 6 | }, 7 | }, 8 | ], 9 | }; 10 | 11 | const getUser = () => jest.fn().mockResolvedValue(data); 12 | 13 | export { getUser }; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/59735993/api_59735993.js: -------------------------------------------------------------------------------- 1 | const getUser = () => 'live api'; 2 | 3 | export { getUser }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/59751925/index.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | export async function main() { 4 | const numbersRes = await axios.get('api/numbers'); 5 | const lettersRes = await axios.get('api/letters'); 6 | return { numbersRes, lettersRes }; 7 | } 8 | -------------------------------------------------------------------------------- /src/stackoverflow/59754838/actionCreator.ts: -------------------------------------------------------------------------------- 1 | import { API_REQUEST_SUCCESS, API_REQUEST_FAILURE } from './actionTypes'; 2 | 3 | export function apiSuccess(data) { 4 | return { 5 | type: API_REQUEST_SUCCESS, 6 | ...data, 7 | }; 8 | } 9 | export function apiError(data) { 10 | return { 11 | type: API_REQUEST_FAILURE, 12 | ...data, 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /src/stackoverflow/59754838/actionTypes.ts: -------------------------------------------------------------------------------- 1 | export const API_REQUEST = 'API_REQUEST'; 2 | export const API_REQUEST_SUCCESS = 'API_REQUEST_SUCCESS'; 3 | export const API_REQUEST_FAILURE = 'API_REQUEST_FAILURE'; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/59759511/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { connect } from 'react-redux'; 3 | 4 | export class HomePage extends Component { 5 | state = {}; 6 | async componentDidMount() { 7 | console.log('a couple of if conditions and an ajax request'); 8 | } 9 | 10 | render() { 11 | return
    HomePage
    ; 12 | } 13 | } 14 | 15 | export default connect()(HomePage); 16 | -------------------------------------------------------------------------------- /src/stackoverflow/59770174/index.tsx: -------------------------------------------------------------------------------- 1 | import throttle from 'lodash/throttle'; 2 | import React from 'react'; 3 | 4 | export function Button({ action }) { 5 | const throttledEvent = throttle(action, 1000, { leading: true, trailing: false }); 6 | 7 | function handlePress() { 8 | console.count('handlePress'); 9 | throttledEvent(); 10 | } 11 | 12 | return ( 13 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /src/stackoverflow/59796811/api.ts: -------------------------------------------------------------------------------- 1 | export const promise1 = (id) => Promise.resolve({ abc: 'real abc' }); 2 | export const promise2 = (data) => Promise.resolve('real promise2 data'); 3 | -------------------------------------------------------------------------------- /src/stackoverflow/59796928/table.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export const Table = ({ number: num }) => { 4 | return
    table: {num}
    ; 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/59825407/authenticationService.ts: -------------------------------------------------------------------------------- 1 | export const authenticationService = { 2 | currentUser: {}, 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/59831697/api.js: -------------------------------------------------------------------------------- 1 | function makeCall() {} 2 | 3 | export default { makeCall }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/59831697/file.js: -------------------------------------------------------------------------------- 1 | import { namedExport } from './nodeModule'; 2 | import api from './api'; 3 | 4 | const apiCall = () => { 5 | return api.makeCall().then( 6 | () => {}, 7 | (error) => { 8 | if (error.status === 403) { 9 | namedExport.logout(); 10 | } 11 | }, 12 | ); 13 | }; 14 | 15 | export default { apiCall }; 16 | -------------------------------------------------------------------------------- /src/stackoverflow/59831697/nodeModule.js: -------------------------------------------------------------------------------- 1 | export const namedExport = { 2 | logout() { 3 | console.log('real implementation'); 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/59853199/api.ts: -------------------------------------------------------------------------------- 1 | export const fetchItems = async () => { 2 | return { data: { items: [] } } as any; 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/59853199/item.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export default function Item(props) { 4 | return ( 5 |
    6 |
    { 8 | props.onClick(); 9 | }} 10 | > 11 | {props.name} 12 |
    13 |
    14 | ); 15 | } 16 | -------------------------------------------------------------------------------- /src/stackoverflow/59853199/listModule.ts: -------------------------------------------------------------------------------- 1 | export const addToSelectList = (item) => { 2 | console.log(item); 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/59867716/index.test.ts: -------------------------------------------------------------------------------- 1 | import { DsBreadcrumb } from './'; 2 | 3 | describe('59867716', () => { 4 | describe('#getAttributes', () => { 5 | it('should pass', () => { 6 | const breadcrumb = new DsBreadcrumb(); 7 | const mEvent = { attributes: { a: { name: 'a name', value: 'a value' } } }; 8 | const actual = breadcrumb.getAttributes(mEvent); 9 | expect(actual).toEqual({ 'a name': 'a value' }); 10 | }); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/59867716/index.ts: -------------------------------------------------------------------------------- 1 | export class DsBreadcrumb { 2 | public getAttributes(el) { 3 | const dataAttrs = {}; 4 | const attributes = el.attributes; 5 | const dataAttributes: any = Object.values(attributes); 6 | 7 | for (const dataAttribute of dataAttributes) { 8 | const keyName = dataAttribute.name; 9 | const keyValue = dataAttribute.value; 10 | dataAttrs[keyName] = keyValue; 11 | } 12 | 13 | return dataAttrs; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/stackoverflow/59871106/student.service.ts: -------------------------------------------------------------------------------- 1 | export class StudentService { 2 | public static getStudentInfo(id) { 3 | return {} as any; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/59873406/index.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | export function main() { 4 | const BASE_URL = 'https://stackoverflow.com'; 5 | const url = 'api'; 6 | const data = {}; 7 | return axios({ 8 | method: 'GET', 9 | url: `${BASE_URL}/${url}`, 10 | data, 11 | }); 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/59886364/index.ts: -------------------------------------------------------------------------------- 1 | export function removeSlot(component: any, selector: string) { 2 | if (component.querySelectorAll(selector).length > 0) { 3 | component.querySelectorAll(selector).forEach((el) => el.remove()); 4 | } else { 5 | console.error(`'${selector}' not found in component '${component.tagName.toLowerCase()}'`); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/stackoverflow/59927917/index.ts: -------------------------------------------------------------------------------- 1 | import { RecommendCards } from './recommendCards'; 2 | 3 | export function main() { 4 | const instance = new RecommendCards(); 5 | document.addEventListener('DOMContentLoaded', () => { 6 | instance.init(); 7 | }); 8 | } 9 | -------------------------------------------------------------------------------- /src/stackoverflow/59927917/recommendCards.ts: -------------------------------------------------------------------------------- 1 | export class RecommendCards { 2 | public init() { 3 | return 'real implementation'; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/59947808/index.js: -------------------------------------------------------------------------------- 1 | export function $isNodeList(input) { 2 | return NodeList.prototype.isPrototypeOf(input); 3 | } 4 | -------------------------------------------------------------------------------- /src/stackoverflow/60008679/index.js: -------------------------------------------------------------------------------- 1 | const { MyClient } = require('./some-service'); 2 | 3 | const invokeMe = async (input1, input2) => { 4 | const client = new MyClient({ 5 | name: 'my-name', 6 | }); 7 | 8 | return await client 9 | .invoke({ 10 | input1, 11 | input2, 12 | }) 13 | .catch((err) => { 14 | throw err; 15 | }); 16 | }; 17 | 18 | module.exports = invokeMe; 19 | -------------------------------------------------------------------------------- /src/stackoverflow/60008679/some-service.js: -------------------------------------------------------------------------------- 1 | class MyClient { 2 | async invoke(input1, input2) { 3 | return 'real response'; 4 | } 5 | } 6 | 7 | module.exports = { MyClient }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/60014903/index.js: -------------------------------------------------------------------------------- 1 | class SomeClass { 2 | skipToBotHandler() { 3 | const skipNav = document.querySelector('.skipnav'); 4 | 5 | skipNav.addEventListener('click', () => { 6 | this.skipLinkFocusHandler(); 7 | }); 8 | } 9 | 10 | skipLinkFocusHandler() {} 11 | } 12 | 13 | export { SomeClass }; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/60018953/index.test.ts: -------------------------------------------------------------------------------- 1 | import main from './'; 2 | import git from 'simple-git/promise'; 3 | 4 | jest.mock('simple-git/promise', () => { 5 | const mGit = { 6 | checkout: jest.fn(), 7 | }; 8 | return jest.fn(() => mGit); 9 | }); 10 | 11 | describe('60018953', () => { 12 | it('should pass', () => { 13 | main(); 14 | expect(git().checkout).toBeCalledWith('https://github.com/user/repo.git'); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/stackoverflow/60018953/index.ts: -------------------------------------------------------------------------------- 1 | import git from 'simple-git/promise'; 2 | 3 | function main() { 4 | git().checkout('https://github.com/user/repo.git'); 5 | } 6 | 7 | export default main; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/63369776/index.js: -------------------------------------------------------------------------------- 1 | import { createStore, applyMiddleware } from 'redux'; 2 | 3 | function rootReducer(state) { 4 | return state; 5 | } 6 | 7 | export default (middlewares) => { 8 | return createStore(rootReducer, applyMiddleware(...middlewares)); 9 | }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/63401335/index.js: -------------------------------------------------------------------------------- 1 | import { useEffect } from 'react'; 2 | 3 | function useNiceHook(data) { 4 | useEffect(() => { 5 | window.analytics.identify(); 6 | }, [data]); 7 | } 8 | 9 | export { useNiceHook }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/63401335/index.test.js: -------------------------------------------------------------------------------- 1 | import { useNiceHook } from './'; 2 | import { renderHook } from '@testing-library/react-hooks'; 3 | 4 | describe('63401335', () => { 5 | it('should pass', () => { 6 | const mAnalytics = { 7 | identify: jest.fn(), 8 | }; 9 | Object.defineProperty(window, 'analytics', { 10 | value: mAnalytics, 11 | }); 12 | const data = {}; 13 | renderHook(() => useNiceHook(data)); 14 | expect(mAnalytics.identify).toBeCalled(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/stackoverflow/63478184/index.test.ts: -------------------------------------------------------------------------------- 1 | import { main, MyInterface } from './'; 2 | import { mocked } from 'ts-jest/utils'; 3 | 4 | describe('63478184', () => { 5 | it('should pass', () => { 6 | const obj: MyInterface = { 7 | someFunc: jest.fn().mockReturnValueOnce('mocked value'), 8 | }; 9 | main(obj); 10 | expect(mocked(obj.someFunc).mock.calls.length).toBe(1); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/63478184/index.ts: -------------------------------------------------------------------------------- 1 | export interface MyInterface { 2 | someFunc: () => void; 3 | } 4 | 5 | export function main(obj: MyInterface) { 6 | return obj.someFunc(); 7 | } 8 | -------------------------------------------------------------------------------- /src/stackoverflow/63484075/index.test.ts: -------------------------------------------------------------------------------- 1 | import { main } from './'; 2 | 3 | describe('63484075', () => { 4 | it('should pass', () => { 5 | const mGetRandomValues = jest.fn().mockReturnValueOnce(new Uint32Array(10)); 6 | Object.defineProperty(window, 'crypto', { 7 | value: { getRandomValues: mGetRandomValues }, 8 | }); 9 | expect(main()).toEqual(new Uint32Array(10)); 10 | expect(mGetRandomValues).toBeCalledWith(new Uint8Array(1)); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/63484075/index.ts: -------------------------------------------------------------------------------- 1 | export function main() { 2 | let byteArray = new Uint8Array(1); 3 | return window.crypto.getRandomValues(byteArray); 4 | } 5 | -------------------------------------------------------------------------------- /src/stackoverflow/63531414/index.ts: -------------------------------------------------------------------------------- 1 | import { Validate } from './validator'; 2 | 3 | export class Controller { 4 | @Validate('params') 5 | async post(request, responseHandler) { 6 | console.log('real post implementation'); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/stackoverflow/63531414/validator.ts: -------------------------------------------------------------------------------- 1 | export const Validate = (params) => { 2 | return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => { 3 | const oFunc = descriptor.value; 4 | descriptor.value = function inner(...args: any[]) { 5 | console.log('real validator decorator implementation'); 6 | // lots of validation 7 | const rval = oFunc.apply(this, args); 8 | return rval; 9 | }; 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /src/stackoverflow/63570675/index.test.ts: -------------------------------------------------------------------------------- 1 | import { main } from './'; 2 | 3 | describe('63570675', () => { 4 | it('should pass', () => { 5 | Object.defineProperty(window.screen, 'orientation', { 6 | value: { type: 'landscape-primary' }, 7 | }); 8 | const actual = main(); 9 | expect(actual).toEqual('landscape-primary'); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/stackoverflow/63570675/index.ts: -------------------------------------------------------------------------------- 1 | export function main() { 2 | const orientation = window.screen.orientation; 3 | return orientation.type; 4 | } 5 | -------------------------------------------------------------------------------- /src/stackoverflow/63607465/Page/Children/Child.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export default function Child() { 4 | return
    abc
    ; 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/63607465/Page/Children/index.js: -------------------------------------------------------------------------------- 1 | export { default } from './Child'; 2 | -------------------------------------------------------------------------------- /src/stackoverflow/63607465/Page/Parent.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Child from './Children'; 3 | 4 | export default class Parent extends React.Component { 5 | constructor(props) { 6 | super(props); 7 | } 8 | 9 | render() { 10 | return ; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/63607465/Page/Parent.spec.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Parent from './Parent'; 3 | 4 | jest.mock('./Children', () => { 5 | return jest.fn(() =>
    mocked child
    ); 6 | }); 7 | 8 | describe('', () => { 9 | let wrapper; 10 | let props = {}; 11 | 12 | describe('render', () => { 13 | it('renders', () => { 14 | wrapper = mount(); 15 | expect(wrapper).toMatchSnapshot(); 16 | }); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /src/stackoverflow/63607465/Page/__snapshots__/Parent.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[` render renders 1`] = ` 4 | 7 | 8 |
    9 | mocked child 10 |
    11 |
    12 |
    13 | `; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/63640360/index.test.ts: -------------------------------------------------------------------------------- 1 | import { mod } from './'; 2 | 3 | describe('63640360', () => { 4 | it('should pass', () => { 5 | const mStorage = { 6 | get: jest.fn().mockImplementationOnce((key, callback) => { 7 | callback(null, 'teresa teng'); 8 | }), 9 | }; 10 | mod.init(mStorage); 11 | const actual = mod.get(); 12 | expect(actual).toBe('teresa teng'); 13 | expect(mStorage.get).toBeCalledWith('key', expect.any(Function)); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/stackoverflow/63640360/index.ts: -------------------------------------------------------------------------------- 1 | const mod = (() => { 2 | let value; 3 | 4 | return { 5 | init: (storage) => { 6 | storage.get('key', (err, v) => { 7 | value = v; 8 | }); 9 | }, 10 | get: () => value, 11 | }; 12 | })(); 13 | 14 | export { mod }; 15 | -------------------------------------------------------------------------------- /src/stackoverflow/63676669/script.js: -------------------------------------------------------------------------------- 1 | var aMyVar = []; 2 | 3 | async function load(bHard) { 4 | console.log(aMyVar); 5 | } 6 | 7 | module.exports = { load }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/63748243/index.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | 3 | function getFile(path): Promise { 4 | return new Promise(function(resolve, reject) { 5 | fs.readFile(path, 'utf8', function(err, success) { 6 | if (err) { 7 | reject(err); 8 | } else { 9 | resolve(success); 10 | } 11 | }); 12 | }); 13 | } 14 | 15 | export { getFile }; 16 | -------------------------------------------------------------------------------- /src/stackoverflow/63797764/classA.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | initialise() {}, 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/63797764/classB.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | initialise() {}, 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/63797764/index.ts: -------------------------------------------------------------------------------- 1 | import classA from './classA'; 2 | import classB from './classB'; 3 | 4 | classA.initialise(); 5 | classB.initialise(); 6 | -------------------------------------------------------------------------------- /src/stackoverflow/63811749/fn.test.ts: -------------------------------------------------------------------------------- 1 | describe('63811749', () => { 2 | beforeEach(() => { 3 | jest.resetModules(); 4 | }); 5 | it('node mock false', async () => { 6 | jest.doMock('detect-node', () => false); 7 | const { myTestFn } = await import('./fn'); 8 | myTestFn(); 9 | }); 10 | 11 | it('node mock true', async () => { 12 | jest.doMock('detect-node', () => true); 13 | const { myTestFn } = await import('./fn'); 14 | myTestFn(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/stackoverflow/63811749/fn.ts: -------------------------------------------------------------------------------- 1 | import isNode from 'detect-node'; 2 | 3 | export const myTestFn = () => console.log({ isNode }); 4 | -------------------------------------------------------------------------------- /src/stackoverflow/63820836/exec.ts: -------------------------------------------------------------------------------- 1 | export interface ExecOptions {} 2 | export const exec = async (command, _, options): Promise => {}; 3 | -------------------------------------------------------------------------------- /src/stackoverflow/63955435/index.ts: -------------------------------------------------------------------------------- 1 | let cachedSecret: any; 2 | 3 | const find = () => { 4 | console.log('cachedSecret:', cachedSecret, typeof cachedSecret); 5 | if (cachedSecret) { 6 | return 'something'; 7 | } else { 8 | return 'something else'; 9 | } 10 | }; 11 | 12 | export { find }; 13 | -------------------------------------------------------------------------------- /src/stackoverflow/63957885/index.test.ts: -------------------------------------------------------------------------------- 1 | import {injectArray} from './' 2 | 3 | const mockFn = jest.fn(); 4 | 5 | describe('injectArray()', () => { 6 | it('returns a new array with the function injected into the objects', () => { 7 | expect(injectArray([{ 8 | name: 'John Doe', 9 | age: 25 10 | }], mockFn)).toEqual([{ 11 | name: 'John Doe', 12 | age: 25, 13 | fn: expect.any(Function) 14 | }]); 15 | }); 16 | }); -------------------------------------------------------------------------------- /src/stackoverflow/63957885/index.ts: -------------------------------------------------------------------------------- 1 | const injectArray = (arr, fn) => { 2 | return arr.map((el) => ({ 3 | ...el, 4 | fn: () => fn(el), 5 | })); 6 | }; 7 | 8 | export {injectArray} -------------------------------------------------------------------------------- /src/stackoverflow/63957901/index.test.ts: -------------------------------------------------------------------------------- 1 | import { Foo } from './'; 2 | 3 | describe('63957901', () => { 4 | it('should pass', () => { 5 | const testProp = {}; 6 | const ct = new Foo.SomeClass(testProp); 7 | expect(ct).toBeInstanceOf(Foo.SomeClass); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /src/stackoverflow/63957901/index.ts: -------------------------------------------------------------------------------- 1 | export module Foo { 2 | export class SomeClass { 3 | constructor(private prop) {} 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/63981693/api.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | const api = axios.create({ 4 | baseURL: 'window.apiPath', 5 | withCredentials: true, 6 | }); 7 | 8 | api.interceptors.request.use( 9 | (config) => { 10 | const newConfig = Object.assign({}, config); 11 | newConfig.headers.Accept = 'application/json'; 12 | 13 | return newConfig; 14 | }, 15 | (error) => Promise.reject(error), 16 | ); 17 | 18 | export default api; 19 | -------------------------------------------------------------------------------- /src/stackoverflow/64003254/index.test.ts: -------------------------------------------------------------------------------- 1 | import fns, { myObject } from './'; 2 | 3 | jest.mock('./', () => { 4 | return { 5 | myObject: { key: 'teresa teng' }, 6 | func1: jest.fn(), 7 | func2: jest.fn(), 8 | }; 9 | }); 10 | 11 | describe('64003254', () => { 12 | it('should pass', () => { 13 | expect(jest.isMockFunction(fns.func1)).toBeTruthy(); 14 | expect(jest.isMockFunction(fns.func2)).toBeTruthy(); 15 | expect(myObject.key).toBe('teresa teng'); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/stackoverflow/64003254/index.ts: -------------------------------------------------------------------------------- 1 | const myFunc = () => { 2 | return { 3 | func1: () => {}, 4 | func2: () => {}, 5 | }; 6 | }; 7 | 8 | export const myObject = { 9 | key: '', 10 | }; 11 | 12 | export default myFunc(); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/64051580/route.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | router.get('', (req, res, next) => { 5 | try { 6 | res.status(200).render('../views/'); 7 | } catch (error) { 8 | next(error); 9 | } 10 | }); 11 | 12 | router.get('*', (req, res, next) => { 13 | try { 14 | res.status(404).render('../views/not-found'); 15 | } catch (error) { 16 | next(error); 17 | } 18 | }); 19 | 20 | module.exports = router; 21 | -------------------------------------------------------------------------------- /src/stackoverflow/64069204/serverRequest.service.js: -------------------------------------------------------------------------------- 1 | import { get } from 'axios'; 2 | 3 | export const serverRequest = { 4 | get: (url, params) => { 5 | try { 6 | return get(url, params); 7 | } catch (err) { 8 | return new Error('server error'); 9 | } 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /src/stackoverflow/64101015/SubsciberProgram.js: -------------------------------------------------------------------------------- 1 | export class SubsciberProgram { 2 | async findBySubscriberId(userId, programId) { 3 | return [1, 2]; 4 | } 5 | async create(userId, programId) { 6 | return { userId, programId }; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/stackoverflow/64148085/Counter.test.tsx: -------------------------------------------------------------------------------- 1 | import { shallow } from 'enzyme'; 2 | import React from 'react'; 3 | import { Counter } from './Counter'; 4 | 5 | describe('64148085', () => { 6 | it('increment counter correctly', () => { 7 | const wrapper = shallow(); 8 | const button = wrapper.find('button'); 9 | button.simulate('click'); 10 | expect(wrapper.find('h2').text()).toBe('1'); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/64148085/Counter.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | 3 | export const Counter = () => { 4 | const [counter, setCounter] = useState(0); 5 | 6 | const handleClick = () => { 7 | setCounter(counter + 1); 8 | }; 9 | 10 | return ( 11 |
    12 |

    {counter}

    13 | 16 |
    17 | ); 18 | }; 19 | -------------------------------------------------------------------------------- /src/stackoverflow/64198516/customhooks.js: -------------------------------------------------------------------------------- 1 | import { useLocation } from 'react-router-dom'; 2 | 3 | export const useCustomLocation = () => { 4 | return new URLSearchParams(useLocation().search); 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/64198516/index.js: -------------------------------------------------------------------------------- 1 | import { useCustomLocation } from './customhooks'; 2 | 3 | export function main() { 4 | return useCustomLocation(); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/64217332/Category.js: -------------------------------------------------------------------------------- 1 | import { isEmpty, isNull } from './validate'; 2 | 3 | export default class Category { 4 | constructor(name) { 5 | this.name = name; 6 | } 7 | 8 | set name(name) { 9 | if (isEmpty(name) || isNull(name)) throw new Error(`The category field needs to be filled`); 10 | this._name = name; 11 | } 12 | get name() { 13 | return this._name; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/stackoverflow/64217332/validate.js: -------------------------------------------------------------------------------- 1 | export const notEmpty = (value) => (value === ' ' ? false : true); 2 | export const isEmpty = (value) => !notEmpty(value); 3 | export const isNull = (value) => value === null; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/64228834/Dashboard.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { useTitle } from './useTitle'; 3 | 4 | export default () => { 5 | useTitle('Dashboard'); 6 | return
    Dashboard
    ; 7 | }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/64228834/useTitle.ts: -------------------------------------------------------------------------------- 1 | import { useDispatch } from 'react-redux'; 2 | 3 | const SET_APP_TITLE = 'SET_APP_TITLE'; 4 | 5 | export const useTitle = (title: string) => { 6 | const dispatch = useDispatch(); 7 | return dispatch({ type: SET_APP_TITLE, title }); 8 | }; 9 | -------------------------------------------------------------------------------- /src/stackoverflow/64271662/index.test.ts: -------------------------------------------------------------------------------- 1 | import { invert, ValidationError } from './'; 2 | 3 | describe('64271662', () => { 4 | it('should throw validation error if string is empty', () => { 5 | expect(() => invert('')).toThrow(ValidationError); 6 | }); 7 | it('should return string', () => { 8 | expect(invert('teresa teng')).toBe('teresa teng'); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/stackoverflow/64271662/index.ts: -------------------------------------------------------------------------------- 1 | export class ValidationError extends Error { 2 | constructor(message) { 3 | super(message); 4 | } 5 | } 6 | export const invert = (str) => { 7 | if (str === '') throw new ValidationError('String must no be empty.'); 8 | return str; 9 | }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/64327189/command-option.js: -------------------------------------------------------------------------------- 1 | class CommandOption { 2 | constructor(commands) { 3 | this.section = commands[0]; 4 | this.method = commands[1]; 5 | this.command1 = commands[2]; 6 | } 7 | 8 | option(optionName) { 9 | return require(`./commands/options/${optionName}`)(this); 10 | } 11 | } 12 | 13 | module.exports = CommandOption; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/64327189/commands/options/host.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrdulin/jest-codelab/d85f355c18a62658a5e153dff8ead691c1c9cf7a/src/stackoverflow/64327189/commands/options/host.js -------------------------------------------------------------------------------- /src/stackoverflow/64344387/functions.js: -------------------------------------------------------------------------------- 1 | module.exports.func1 = async (param1, param2) => { 2 | console.log('real func1 implementation'); 3 | }; 4 | module.exports.func2 = async (param) => { 5 | console.log('real func2 implementation'); 6 | }; 7 | -------------------------------------------------------------------------------- /src/stackoverflow/64344387/functions.test.js: -------------------------------------------------------------------------------- 1 | const app = require('./functions.js'); 2 | 3 | describe('64344387', () => { 4 | it('should pass', async () => { 5 | jest.spyOn(app, 'func2').mockImplementationOnce(async () => null); 6 | const actual = await app.func2(); 7 | expect(actual).toBeNull(); 8 | expect(app.func2).toBeCalled(); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/stackoverflow/64382021/handler/handler.js: -------------------------------------------------------------------------------- 1 | export function Handler(windowAlias, documentAlias) { 2 | this.windowAlias = windowAlias; 3 | this.documentAlias = documentAlias; 4 | 5 | this.attachEventListners = function(globalSet) { 6 | // do something 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /src/stackoverflow/64382021/main.js: -------------------------------------------------------------------------------- 1 | import { Handler } from './handler/handler.js'; 2 | 3 | const windowAlias = 'windowAlias'; 4 | const documentAlias = 'documentAlias'; 5 | var lh = new Handler(windowAlias, documentAlias); 6 | -------------------------------------------------------------------------------- /src/stackoverflow/64382021/main.test.js: -------------------------------------------------------------------------------- 1 | import './main'; 2 | import { Handler } from './handler/handler.js'; 3 | jest.mock('./handler/handler.js', () => { 4 | return { Handler: jest.fn() }; 5 | }); 6 | 7 | describe('64382021', () => { 8 | it('should pass', async () => { 9 | expect(Handler).toBeCalledWith('windowAlias', 'documentAlias'); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/stackoverflow/64385009/index.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | 3 | async function getUser(id) { 4 | const user = await axios.get('./user'); 5 | return user; 6 | } 7 | module.exports = { 8 | getUser, 9 | }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/64386858/app.js: -------------------------------------------------------------------------------- 1 | const crypto = require('crypto'); 2 | 3 | function main() { 4 | const API_TOKEN = 'API_TOKEN'; 5 | const signature = '123'; 6 | const body = {}; 7 | 8 | const hash = crypto 9 | .createHmac('sha256', API_TOKEN) 10 | .update(JSON.stringify(body)) 11 | .digest('hex'); 12 | 13 | if (hash === signature) { 14 | console.log('verified successfully. Implement next logic'); 15 | } 16 | } 17 | 18 | module.exports = main; 19 | -------------------------------------------------------------------------------- /src/stackoverflow/64473533/config.js: -------------------------------------------------------------------------------- 1 | export const DELAY_SECONDS = 5; 2 | -------------------------------------------------------------------------------- /src/stackoverflow/64473533/main.js: -------------------------------------------------------------------------------- 1 | import { DELAY_SECONDS } from './config'; 2 | 3 | function main() { 4 | return DELAY_SECONDS; 5 | } 6 | 7 | export { main }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/64477184/index.ts: -------------------------------------------------------------------------------- 1 | import { useLocation } from 'react-router-dom'; 2 | 3 | export function usePageViews() { 4 | return useLocation(); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/64549093/index.test.ts: -------------------------------------------------------------------------------- 1 | import * as mod from './'; 2 | 3 | console.log(mod); 4 | 5 | describe('64549093', () => { 6 | it('should pass', () => { 7 | const BarConstructorMock = jest.spyOn(mod as any, 'Bar').mockImplementationOnce(() => { 8 | console.log('fake Bar constructor implmentation'); 9 | }); 10 | new mod.default(); 11 | expect(BarConstructorMock).toBeCalled(); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /src/stackoverflow/64549093/index.ts: -------------------------------------------------------------------------------- 1 | export default class Foo { 2 | constructor() { 3 | new exports.Bar(); 4 | } 5 | } 6 | 7 | class Bar { 8 | constructor() { 9 | console.log('real Bar constructor implmentation'); 10 | } 11 | } 12 | 13 | exports.Bar = Bar; 14 | -------------------------------------------------------------------------------- /src/stackoverflow/64564148/setAuthToken.test.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | import setAuthToken from './setAuthToken'; 3 | 4 | jest.unmock('axios'); 5 | 6 | describe('setAuthToken utility function.', () => { 7 | test('Sets the axios header, x-auth-token, with a token.', () => { 8 | let token = 'test token'; 9 | setAuthToken(token); 10 | expect(axios.defaults.headers.common['x-auth-token']).toBe('test token'); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/64564148/setAuthToken.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | const setAuthToken = (token) => { 4 | if (token) { 5 | axios.defaults.headers.common['x-auth-token'] = token; 6 | } else { 7 | delete axios.defaults.headers.common['x-auth-token']; 8 | } 9 | }; 10 | 11 | export default setAuthToken; 12 | -------------------------------------------------------------------------------- /src/stackoverflow/64575307/send.js: -------------------------------------------------------------------------------- 1 | const admin = require('firebase-admin'); 2 | 3 | async function myCloudFn(email) { 4 | const authUser = await admin.auth().getUserByEmail(email); 5 | return authUser; 6 | } 7 | 8 | module.exports = { myCloudFn }; 9 | -------------------------------------------------------------------------------- /src/stackoverflow/64768906/app.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | 4 | module.exports = app; 5 | -------------------------------------------------------------------------------- /src/stackoverflow/64768906/www.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | const app = require('./app'); 3 | 4 | http.createServer(app).listen(process.env.SERVER_PORT || 3000); 5 | -------------------------------------------------------------------------------- /src/stackoverflow/64811936/collection.ts: -------------------------------------------------------------------------------- 1 | export function collection(name: string) { 2 | return 'real implementation'; 3 | } 4 | -------------------------------------------------------------------------------- /src/stackoverflow/64811936/index.ts: -------------------------------------------------------------------------------- 1 | import { collection } from './collection'; 2 | 3 | type Collection = any; 4 | 5 | export const getClient = (): Collection => { 6 | return collection(process.env.DB_COLLECTION || 'Null'); 7 | }; 8 | -------------------------------------------------------------------------------- /src/stackoverflow/64817280/Card.jsx: -------------------------------------------------------------------------------- 1 | export default function Card({ card }) { 2 | return
    {card.name}
    ; 3 | } 4 | -------------------------------------------------------------------------------- /src/stackoverflow/64817280/CardList.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Card from './Card'; 3 | 4 | export default function CardList({ cards }) { 5 | return ( 6 |
    7 | {cards.map((card) => { 8 | return ; 9 | })} 10 |
    11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/stackoverflow/64817280/CardList.test.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import CardList from './CardList'; 4 | 5 | it('renders without crashing', () => { 6 | const cards = [{ id: 1, name: 'teresa teng' }]; 7 | const div = document.createElement('div'); 8 | ReactDOM.render(, div); 9 | }); 10 | -------------------------------------------------------------------------------- /src/stackoverflow/64858662/example.js: -------------------------------------------------------------------------------- 1 | import Logger from 'logging-library'; 2 | 3 | export default function example() { 4 | Logger.error(new Error('Example Error')); 5 | } 6 | -------------------------------------------------------------------------------- /src/stackoverflow/64975712/foo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello Jest! 4 | 5 | 6 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/stackoverflow/64988386/index.jsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Link = styled.a` 4 | color: #fff; 5 | `; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/64988386/index.test.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import { Link } from '.'; 4 | 5 | describe('Link', () => { 6 | it('should display color on the link', () => { 7 | const { getByRole } = render(Test); 8 | const link = getByRole('link', { name: /test/i }); 9 | expect(link).toHaveStyle(`color: #fff`); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/stackoverflow/65042421/index.test.ts: -------------------------------------------------------------------------------- 1 | const t1 = () => 't'; 2 | const t2 = () => 't'; 3 | 4 | test.each([t1, t2])('test function %p', (f) => { 5 | console.log(`test function ${f.name}`); 6 | expect(f()).toBe('t'); 7 | }); 8 | -------------------------------------------------------------------------------- /src/stackoverflow/65049305/app.ts: -------------------------------------------------------------------------------- 1 | import config from './config'; 2 | 3 | export default () => { 4 | return config.foo; 5 | }; 6 | -------------------------------------------------------------------------------- /src/stackoverflow/65049305/config.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | foo: 'bar', 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/65097473/ValueClass.js: -------------------------------------------------------------------------------- 1 | class ValueClass { 2 | async getValue() { 3 | const a = 'a'; 4 | const b = 'b'; 5 | return a + b; 6 | } 7 | } 8 | 9 | module.exports = { 10 | ValueClass, 11 | }; 12 | -------------------------------------------------------------------------------- /src/stackoverflow/65097473/component.js: -------------------------------------------------------------------------------- 1 | const { ValueClass } = require('./ValueClass'); 2 | 3 | const component = async () => { 4 | const objValueClass = new ValueClass(); 5 | const accessValue = await objValueClass.getValue(); 6 | console.log('accessValue###', accessValue); 7 | }; 8 | 9 | module.exports = component; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/65112057/deivce.ts: -------------------------------------------------------------------------------- 1 | export default class Devices { 2 | public static connectAudioDevice(device?: InputDeviceInfo): Promise { 3 | return new Promise((resolve, reject) => { 4 | navigator.mediaDevices 5 | .getUserMedia({ audio: true }) 6 | .then((stream) => { 7 | resolve(stream); 8 | }) 9 | .catch((error) => { 10 | resolve(error); 11 | }); 12 | }); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/stackoverflow/65135435/index.test.ts: -------------------------------------------------------------------------------- 1 | import { pause } from './'; 2 | 3 | jest.useFakeTimers(); 4 | 5 | describe('65135435', () => { 6 | it('should pass', async () => { 7 | const setTimeoutSpy = jest.spyOn(window, 'setTimeout'); 8 | const pausePromise = pause({ time: 2500 }); 9 | 10 | jest.runAllTimers(); 11 | 12 | await pausePromise; 13 | expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), 2500); 14 | expect(setTimeoutSpy).toHaveBeenCalledTimes(1); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/stackoverflow/65135435/index.ts: -------------------------------------------------------------------------------- 1 | export const pause = ({ time } = {} as any) => { 2 | const pauseTime = time || 500; 3 | 4 | return new Promise((resolve) => { 5 | setTimeout(() => { 6 | resolve(); 7 | }, pauseTime); 8 | }); 9 | }; 10 | -------------------------------------------------------------------------------- /src/stackoverflow/65145829/actions.js: -------------------------------------------------------------------------------- 1 | export const changeBackgroundType = 'changeBackgroundType'; 2 | export const addGradientStart = 'addGradientStart'; 3 | export const addGradientEnd = 'addGradientEnd'; 4 | export const addUrl = 'addUrl'; 5 | -------------------------------------------------------------------------------- /src/stackoverflow/65148503/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.json", 3 | "compilerOptions": { 4 | "strictPropertyInitialization": false, 5 | "strictNullChecks": false 6 | } 7 | } -------------------------------------------------------------------------------- /src/stackoverflow/65148503/user.ts: -------------------------------------------------------------------------------- 1 | import mongoose from 'mongoose'; 2 | const { Schema } = mongoose; 3 | 4 | export interface IUser extends mongoose.Document { 5 | id_test: string; 6 | password: string; 7 | } 8 | 9 | const UserSchema = new Schema({ 10 | id_test: String, 11 | password: String, 12 | }); 13 | 14 | const User = mongoose.model('User', UserSchema); 15 | 16 | export { User }; 17 | -------------------------------------------------------------------------------- /src/stackoverflow/65167311/axiosInstance.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrdulin/jest-codelab/d85f355c18a62658a5e153dff8ead691c1c9cf7a/src/stackoverflow/65167311/axiosInstance.js -------------------------------------------------------------------------------- /src/stackoverflow/65167311/config.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrdulin/jest-codelab/d85f355c18a62658a5e153dff8ead691c1c9cf7a/src/stackoverflow/65167311/config.js -------------------------------------------------------------------------------- /src/stackoverflow/65174562/index.test.ts: -------------------------------------------------------------------------------- 1 | describe('65174562', () => { 2 | it('should pass', () => { 3 | const insertedData = { 4 | id: '123', 5 | lastModifiedDate: new Date('2019-08-28'), 6 | }; 7 | expect(insertedData).toEqual({ 8 | id: expect.any(String), 9 | lastModifiedDate: expect.any(Date), 10 | }); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/stackoverflow/65179710/apiLambda.test.js: -------------------------------------------------------------------------------- 1 | const { runLambda } = require('./testUtils'); 2 | 3 | describe('on new query', () => { 4 | it('returns data', async (done) => { 5 | await runLambda( 6 | ['person', ['John']], 7 | (query) => { 8 | expect(query).toHaveBeenCalledWith(['person', ['John']], null); 9 | }, 10 | done, 11 | ); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /src/stackoverflow/65207598/helpers.js: -------------------------------------------------------------------------------- 1 | const searchValue = async (fooId, db) => { 2 | return await db.collection('foos').findOne({ fooId: fooId }); 3 | }; 4 | -------------------------------------------------------------------------------- /src/stackoverflow/65220363/index.ts: -------------------------------------------------------------------------------- 1 | import SendBird from 'sendbird'; 2 | 3 | const API_Token = 'test api token'; 4 | const APP_ID = 'test api id'; 5 | 6 | export const sbConnect = (userId) => { 7 | return new Promise((resolve, reject) => { 8 | const sb = new SendBird({ appId: APP_ID }); 9 | sb.connect(userId, API_Token, (user, error) => { 10 | if (error) { 11 | reject(error); 12 | } else { 13 | resolve(user); 14 | } 15 | }); 16 | }); 17 | }; 18 | -------------------------------------------------------------------------------- /src/timer-mock/module.ts: -------------------------------------------------------------------------------- 1 | function timerGame(callback?: () => void) { 2 | console.log('Ready....go!'); 3 | setTimeout(() => { 4 | console.log('Times up -- stop!'); 5 | if (callback) { 6 | callback(); 7 | } 8 | }, 1000); 9 | } 10 | 11 | export { timerGame }; 12 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": ["tslint:recommended", "tslint-config-prettier"], 4 | "rules": { 5 | "quotemark": false, 6 | "no-console": false, 7 | "trailing-comma": false, 8 | "ordered-imports": false, 9 | "object-literal-sort-keys": false, 10 | "arrow-parens": false 11 | } 12 | } 13 | --------------------------------------------------------------------------------