投稿時間:2023-03-05 00:14:12 RSSフィード2023-03-05 00:00 分まとめ(16件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
js JavaScriptタグが付けられた新着投稿 - Qiita 適応型ハフマンエンコード実装 https://qiita.com/z0ero/items/742deb5aeb269dbd87a7 雑記 2023-03-04 23:50:00
js JavaScriptタグが付けられた新着投稿 - Qiita ChatGPTのAPIをGASで叩き、SlackBotで会話できるようにする https://qiita.com/Keichan_15/items/a4facca87d178f356397 keichan 2023-03-04 23:01:15
Ruby Rubyタグが付けられた新着投稿 - Qiita ruby の popen で sh: -c: line 0: syntax error near unexpected token `(' https://qiita.com/hidenorly/items/19fdfc1ae8565606cf62 shcline 2023-03-04 23:46:13
Ruby Rubyタグが付けられた新着投稿 - Qiita RSpec Mocksのチートシート https://qiita.com/mew3880/items/0e27af4c0afbaf134479 rspec 2023-03-04 23:30:44
Git Gitタグが付けられた新着投稿 - Qiita 【Error】Gitにpushできない「error: failed to push some refs to...」 https://qiita.com/LB16B/items/772ffcb0ecc88eebaae3 error 2023-03-04 23:59:15
Ruby Railsタグが付けられた新着投稿 - Qiita RSpec Mocksのチートシート https://qiita.com/mew3880/items/0e27af4c0afbaf134479 rspec 2023-03-04 23:30:44
Ruby Railsタグが付けられた新着投稿 - Qiita Rails Nuxtでcarrierwaveを使って画像を保存したときのはまったポイント https://qiita.com/taguchi_study/items/667a6d8bd1097c58d846 carrierwave 2023-03-04 23:29:49
技術ブログ Developers.IO [AWS CDK] Amazon CognitoでHosted UIを実装する際にハマったこと https://dev.classmethod.jp/articles/cognito-hosted-ui-signup-error/ amazoncognito 2023-03-04 14:57:37
海外TECH DEV Community Test React component that fetching data https://dev.to/thexdev/test-react-component-that-fetching-data-390p Test React component that fetching data TL DRWe are going to use Mock Service Worker to fake the API So instead directly calling the API or mock the window fetch it s better to mock the server behaviour It gives us a sandbox to play with the API server without polluting the window fetch and no need to setup test API server for testing purpose Thanks to Artem Zakharchenko that has made a useful tools IntroductionYou have created a beautiful Feed feature on your site and now you want to test that feature Your code is look like thisimport React from react function Feed const feeds setFeeds React useState React useEffect gt const ctl new AbortController fetch then res gt res json then res gt setFeeds res data catch gt Log the error return cleanup ctl abort return lt ul gt feeds map feed gt lt li gt feed title lt li gt lt ul gt Though it s really simple frature where you want to show users feed to the UI Somehow you confused about how to test the feature because you must fetch the feeds data from the API but since this is a test you won t it calls directly to the API The JourneyNow you are searching possible solutions on the Internet Because you use React and of course use Jest and testing library it is default setup from CRA someone suggest you to mock the window fetch object You intersted and put the solution in your test like this Import all dependencies const MOCK FEEDS Feed objects here beforeAll gt jest spyOn window fetch describe Feed Feature Test gt it should shows users feed gt window fetch mockResolvedValueOnce ok true json async gt data MOCK FEEDS Your testing goes here You test the code and it looks green meaning your test is pass and you happy with that Tomorrow has come You forgot about the empty state UI for Feed feature and today you made it Because the empty state UI need en error HTTP NOT FOUND you need to refactor the test Import all dependencies const MOCK FEEDS Feed objects here const MOCK FEEDS NOT FOUND beforeAll gt jest spyOn window fetch beforeEach gt jest restoreAllMocks describe Feed Feature Test gt it should shows empty state UI when feeds not found gt window fetch mockResolvedValueOnce ok false status json async gt data MOCK FEEDS NOT FOUND Your testing goes here it should shows users feed gt window fetch mockResolvedValueOnce ok false json async gt data MOCK FEEDS Your testing goes here Your test is passes and you happy again The next morning you received calls from project manager He want you to add a like ️ button and you do it From this task you have to update the feature to fetch two API endpoints First you must use the GET feeds and then POST feeds id like to perform like this feed After adding some codes you refactor the test again but realise that the mocked fetch doesn t care of the URL What ever API endpoint you hit it always returns the same response and potential a bugs on the future The test now is look like this Import all dependencies const MOCK FEEDS Feed objects here const MOCK FEEDS NOT FOUND beforeAll gt jest spyOn window fetch beforeEach gt window fetch mockImplementation async url config gt switch url case feeds return ok true json async gt MOCK FEEDS case feeds like return ok true json async gt liked true default throw new Error Unhandled request url describe Feed Feature Test gt it should shows empty state UI when feeds not found gt Your testing goes here it should shows users feed gt Your testing goes here it should able to like the feed gt Your testing goes here The tests are passes except the first one You asking why then realise there is no request handler for GET feeds with http status The SolutionLuckly there is a tool called Mock Service Worker It is a mocking tool for API and live in the network level Simply imagine that you can mock your API server and use it inside your test without makes you headache And the interesting part of this are Support Rest API and GraphQLSupport Node and Browser meaning you can use it with Express etc And many more Enough for explaining let s install the requirement and refactor the tests First install the msw npm i D mswTo use the MSW you need to make request handlers with specific HTTP method and URL So it gives you an ability to make GET feeds and GET feeds It also support URL parameter like this feeds feedId like Now update the test like this Import all dependencies import rest from msw import setupServer from msw node const MOCK FEEDS Feed objects here const MOCK FEEDS NOT FOUND const url path gt path const defaultHandlers rest get url path req res ctx gt return res ctx json MOCK FEEDS rest get url path gt return res ctx status ctx json MOCK FEEDS NOT FOUND const server setupServer defaultHandlers describe Feed Feature Test gt beforeAll gt server listen afterEach gt server resetHandlers afterAll gt server close it should shows empty state UI when feeds not found gt Your testing goes here it should shows users feed gt Your testing goes here it should able to like the feed gt Adds the POST feeds feedId like request handler as a part of this test server use rest post url feeds feedId like req rest ctx gt return res ctx json liked true Your testing goes here Boom your tests are passes Not only the tests are passes it also provide better DX because you can easily create powerful URL routing You can also split the handlers into another file to prevent writing the handlers repeatedly Making it reusable across all tests Not only provide better DX MSW also offers you HTTP Cookie and other HTTP features Awesome ConclusionMocking and testing HTTP request is one of challenging part but MSW comes with powerful feature cross platform and use simple approach to tackle this problem MSW provide native like approach by intercepting the network and returns the handlers we made instead of the real one Prevent you to pollute the window fetch by mocking it and potentially caused bugs mswjs msw Seamless REST GraphQL API mocking library for browser and Node js Mock Service WorkerMock Service Worker MSW is a seamless REST GraphQL API mocking library for browser and Node js FeaturesSeamless A dedicated layer of requests interception at your disposal Keep your application s code and tests unaware of whether something is mocked or not Deviation free Request the same production resources and test the actual behavior of your app Augment an existing API or design it as you go when there is none Familiar amp Powerful Use Express like routing syntax to capture requests Use parameters wildcards and regular expressions to match requests and respond with necessary status codes headers cookies delays or completely custom resolvers I found MSW and was thrilled that not only could I still see the mocked responses in my DevTools but that the mocks didn t have to be written in a Service Worker and could instead live alongside the rest of my app … View on GitHub 2023-03-04 14:18:59
Apple AppleInsider - Frontpage News Apple Watch ban threat, layoffs, and Jony Ive's red nose -- February 2023 in review https://appleinsider.com/articles/23/03/04/apple-watch-ban-threat-layoffs-and-jony-ives-red-nose----february-2023-in-review?utm_medium=rss Apple Watch ban threat layoffs and Jony Ive x s red nose February in reviewDespite not launching any devices Apple had a surprisingly packed month fighting for the Apple Watch while Jony Ive helped out with charity and Rihanna played the Super Bowl for Apple Music Honestly you re lucky to still be wearing an Apple Watch Wild claims in February did not quite reach the stage of saying you had hours to turn in your Watch to the authorities but there was serious talk of a ban on Apple selling new ones It was serious in that the ban was always described very seriously and it was based on word from the White House Or rather it was based on how the White House pointedly did not say a word Read more 2023-03-04 14:03:35
ニュース BBC News - Home Bakhmut: Fighting in the street but Russia not in control - deputy mayor https://www.bbc.co.uk/news/world-europe-64846666?at_medium=RSS&at_campaign=KARANGA strategic 2023-03-04 14:46:08
ニュース BBC News - Home Kuenssberg: Sunak can't escape past Tory horrors https://www.bbc.co.uk/news/uk-politics-64835929?at_medium=RSS&at_campaign=KARANGA minister 2023-03-04 14:18:14
ニュース BBC News - Home Loud bang prompts calls to Leicestershire Police https://www.bbc.co.uk/news/uk-england-leicestershire-64847214?at_medium=RSS&at_campaign=KARANGA sonic 2023-03-04 14:46:11
ニュース BBC News - Home Rafael Viñoly: Uruguayan architect of London's 'Walkie Talkie' dies aged 78 https://www.bbc.co.uk/news/world-latin-america-64848302?at_medium=RSS&at_campaign=KARANGA ground 2023-03-04 14:28:45
ニュース BBC News - Home Channel ferry blaze: Investigation launched after Isle of Innisfree towed to Calais https://www.bbc.co.uk/news/uk-england-kent-64847029?at_medium=RSS&at_campaign=KARANGA engine 2023-03-04 14:25:37
ニュース BBC News - Home Man City 2-0 Newcastle: Phil Foden stars as City keep pressure up in Premier League title race https://www.bbc.co.uk/sport/football/64768044?at_medium=RSS&at_campaign=KARANGA Man City Newcastle Phil Foden stars as City keep pressure up in Premier League title racePhil Foden s superb solo goal helps Manchester City see off Newcastle and ensures the defending champions keep up the pressure on Premier League leaders Arsenal 2023-03-04 14:51:11

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)