<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by duke mai on Medium]]></title>
        <description><![CDATA[Stories by duke mai on Medium]]></description>
        <link>https://medium.com/@mrducmv88?source=rss-3d66ac01cb2d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WkwCfFUR_YmKmMv3.png</url>
            <title>Stories by duke mai on Medium</title>
            <link>https://medium.com/@mrducmv88?source=rss-3d66ac01cb2d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 07:52:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mrducmv88/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Testing a react application with Jest]]></title>
            <link>https://medium.com/@mrducmv88/testing-a-react-application-with-jest-aa555a69a52e?source=rss-3d66ac01cb2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa555a69a52e</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[duke mai]]></dc:creator>
            <pubDate>Fri, 21 Jul 2017 22:09:07 GMT</pubDate>
            <atom:updated>2017-07-21T22:09:07.270Z</atom:updated>
            <content:encoded><![CDATA[<p>this is the second part of my post about web development using React, Redux stacks with docker and automated testing. You can find my first episode <a href="https://medium.com/@mrducmv88/web-development-using-react-redux-stacks-with-docker-and-automated-testing-1cb38be72914">here</a></p><p>In the previous post, I already explained the stacks including docker, express, mongodb, mongoose, ES6 for developing backend. Docker, eslint with AirBnB rules, swagger were utilized to enforce the application. The logic of the application was ensured by tests running on Jest. On the other hand, front-end side was equipped with a wide using framework React and its famous accompany Redux. In addition, some middlewares are Redux Thunk, Redux Promise, were chosen to enhance the power. client side logic is also ensured by tests written on Jest. At the last mile stone, I was having some problems with testing at client side.</p><p>The first problem I had was testing redux integration. I found a very good library to mockup redux store, redux-mock-store. With this library, I could easily test redux actions, redux reducers with mocking a store. But later I decided to test the whole application without testing separately redux.</p><p>The most headache problem I was having is testing ajax requests. In my application, there are several components fetched content from server asynchronously by dispatching redux thunk actions. this is quite common technique when working with react and redux. However, it leads to headache matters when running tests without real browser environments. I managed to solve all problems related to ajax testing steps by steps. I will make a separate session for explaining detail about problems and the solutions.</p><p><strong>Problem 1: mockup ajax requests,</strong></p><p>there are many posts on internet and each of them present a different way to solve this problem. I also have a solution myself. I start my solution with <strong>nock</strong> which provides abilities to inject into the request process. The limitation in my opinion of nock is that it hijacks only full domain requests which means your relative requests are not modified by nock. I overcome this matter by using axios to make ajax requests and axios provides a way to specify a domain by default. this line of code axios.defaults.baseURL = … will make the trick. And I have spent 2 days to realize that I need this assignment axios.defaults.adapter = httpAdapter where httpAdapter from ‘axios/lib/adapters/http’. The previous code will help jest running axios without any network exceptions.</p><p>Nock helps me to interrupt http requests. the next step is to prepare data for mocked up requests. At this step, I used super tests requests to fetch test data made from server tests. Responses from super tests requests will be injected into nock requests. In the end I have mocked requests with real responses from server. Now, it is the time for problem 2</p><p><strong>Problem 2: verifying the application after having data fetched through ajax requests.</strong></p><p>this matter was really tough since I did not have any clue when ajax requests finish and when redux updates react components. I have thought of several alternatives such as basing on store subscribe or delay verification. In the end, I decided to use a delay technique. Basically, delay technique uses setTimeout as essential. However, jest does not work well with setTimeout if you do not have some tricks. And a function that returns a promise within its is a setTimeout will do the trick.</p><p>Finally my tests look like that, Render App =&gt; delay 100ms =&gt; trigger some actions =&gt; delay 100ms =&gt; getState =&gt; verify Components and state.</p><p><strong>Problem 3: test rendering React Component and events on React Component</strong></p><p>this problem was pretty easily solved by using Enzyme to render React Components and trigger events. Along the time working with the project, I have suffered some issues when interacting with React Components that I needed to add some console logs to know what extra data needed when triggering events. In almost cases, Enzyme does all the job for you.</p><p><strong>Conclusion</strong></p><p>wrapping up, I shared a story of my own experience on building a web application using the following stacks</p><ul><li>Mongo DB, mongoose — database</li><li>Express — web server</li><li>Webpack, Gulp — preprocess js, css</li><li>Nodemon — for development</li><li>Eslint, AirBnB rules— consistent coding</li><li>Jest — test runner</li><li>Docker — sandbox hosting</li><li>Swagger — api explanation</li><li>SuperTest — mockup requests at server</li><li>React — essential clientside business</li><li>Redux — maintain states at clientside</li><li>Redux-Router — routing at clientside</li><li>Redux-thunk — enhancing power to action creators</li><li>Axios — making requests.</li><li>Nock — mocking requests at clientside.</li><li>Delay to verify React Components</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa555a69a52e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web development using React, Redux stacks with docker and automated testing]]></title>
            <link>https://medium.com/@mrducmv88/web-development-using-react-redux-stacks-with-docker-and-automated-testing-1cb38be72914?source=rss-3d66ac01cb2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cb38be72914</guid>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[duke mai]]></dc:creator>
            <pubDate>Fri, 07 Jul 2017 22:28:51 GMT</pubDate>
            <atom:updated>2017-07-07T22:28:51.226Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, the web development world has observed the mass evolution of NodeJs, React. It is no doubt that Nodejs and React bring a new trend of web development. In my latest project, I have a chance to apply all new cool things in Nodejs ecosystem. The project started with a typical combination.</p><p><strong>Server Side: </strong>mongodb, mongoose for DB interactions, express</p><p><strong>Client Side: </strong>React, Redux, Redux Thunk and some other middlewares for Redux, Twitter Bootstrap 3.</p><p><strong>Build Tools: </strong>webpack 2 and gulp.</p><p>so this is a typical setup for a starter. To make code more consistent, Eslint and AirBNB rules collection are highly recommended .The next thing, I learnt and applied for this project is docker. I believe that docker is a new star from the last year. I used docker compose for setting up Mongo DB at first. With docker and few lines to docker compose file, then all needed dependencies for development were resolved in one blinking. Phew, I love docker so much. Docker also eases our pains when deployment. Any one can easily start a project without downloading every piece of dependencies. Docker will help you.</p><p>The project, I have been working on, has some APIs. And Swagger is a perfect tool for demonstrating the uses of APIs. Again, docker makes uses for setting up Swagger in one second. Swagger container is available on docker repository so one click will install it on your local and together with “swagger-jsdoc” then a beautiful description UI of APIs is ready.</p><p>The last pitch of the project is automated testing. Automated testing is not the same as automation test. I used jest, a test runner published by facebook for running tests. Beside of unit tests for each functions in the project. I composed a bunch of test suites which will act as normal users and walk through all flows of the system. I have been suffering from some pains when writing tests which are: testing against database, testing APIs.</p><p>The solutions for the two problems are: testing against database — create a new docker container for testing purpose only, testing APIs — super test is a perfect library for it.</p><p>In the end, I have a bunch of tests which covering all flows of the system and it takes 5 seconds to run all the tests. I am happy that the result saves me hours to verify whenever a change to the code is made.</p><p>at this moment, I am continuing with tests for front-end using React. In my hands, I have jest, enzyme, axios mocker for writing tests. However, I am having a trouble with testing ajax requests executed in React Components. It is really a headache. I will write another article for solving this problem.</p><p>Finally, Express-React-MongoDB is a popular set. Docker is a cargo which you should definitely need to know for carrying all your dependencies. Beside that, jest is to make your code perfectly works. Eslint is also a useful recommendation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cb38be72914" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Services Worker, a new way to boost up your websites]]></title>
            <link>https://medium.com/@mrducmv88/services-worker-a-new-way-to-boost-up-your-websites-8598828a5afc?source=rss-3d66ac01cb2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8598828a5afc</guid>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[duke mai]]></dc:creator>
            <pubDate>Tue, 11 Apr 2017 16:19:34 GMT</pubDate>
            <atom:updated>2017-04-11T16:19:34.955Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I started an investigation about working offline with Chrome and I was so lucky to join a google event which gave me a great opportunity to explore on cool technique for making the sites faster. Google named it as services worker.</p><p>you can read more at <a href="https://developers.google.com/web/fundamentals/getting-started/primers/service-workers.">https://developers.google.com/web/fundamentals/getting-started/primers/service-workers.</a></p><p>it is a really amazing technique. Basically, the technique provides a worker for acting as a cache proxy. It will cache your urls .This cache proxy is extremely useful to serve data instantly. To adapt with the technique, we should break down our websites into two parts. The first part is called shell-UI containing static parts or seldom update parts in the sites. The second part is about data on the sites that need up to date whenever users request. By caching static parts, then everything is served instantly when requests come.</p><p>We start using services worker into our Episerver CMS. From technical point of view, a Episerver CMS is a combination of iframes and many of them are actually never changed. So it is perfect fit for services worker. Currently the implementation is under construction. So far, we got a very positive result when applying the technique.</p><p>At this moment, services worker are implemented in Chrome only but it soon will be implemented by FireFox. So it is a promising future for start using services worker.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8598828a5afc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>