Wednesday, October 25, 2017

How Much Do #Instagram Ads Cost? - #infographic

In 2017 everyone is waxing lyrical about visual content. From video ads to sponsored posts on Instagram, if you have a product — you should probably be selling it with amazing visual imagery! If you’re not convinced that visual content is the medium of the future, check out some of these...

[ This is a content summary only. Visit our website http://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Irfan Ahmad via Digital Information World

#313: The state of Chrome and the Web Platform today

Frontend Focus
Issue 313 — October 25, 2017
The story behind the CSS Grid spec, and the more than 20-year process that led to today.
Aaron Gustafson

Starts from the usual basics (title, charset, etc.) but works up to a significant number of meta and link tags useful in various situations.
Josh Buchea

The popular webdev tool Firebug surely inspired Chrome’s DevTools but has now reached end-of-life. Here’s a look back at what it brought us during its 12-year lifespan.
Jan Honza Odvarko

Get started with modern developers solution for charting and visualization. ZingChart is fully featured, integrates with popular JS frameworks, & has a robust API with endless customization options.
ZingChart   Sponsor

Ben Galbraith, leader of the Chrome Web Platform team, and Dion Almaer, Google Engineering Director, discuss the state of Chrome and the Web Platform today.
Google Chrome Developers

Addy Osmani runs through loading best practices for diagnosing and making real-world sites load ‘instantly’. Filmed at the Chrome Dev Summit 2017.
Google Chrome Developers

GitHub uses this for scanning for inaccessible elements within its interfaces during development.
GitHub

Jobs

In Brief

CKEditor 5 Rich Text Editor Released news
Frederico Knabben

Get FlexGrid, The Best JavaScript Data Grid: Fast, Flexible, No dependencies 
With no dependencies and a small footprint, Wijmo FlexGrid is built for speed and extensibility.
GrapeCity Wijmo  Sponsor

Alt-texts: The Ultimate Guide to 'alt' Attribute Text tutorial
Daniel Göransson

Building an Elegant Progress Ring with SVG tutorial
.. and then using it as a Web Component or in Vue or React.
Jeremias Menichelli

Animating a Blur Efficiently tutorial
Google Developers

My Approach to Using z-index tutorial
A recommendation to categorise all uses of z-index as either local or global.
David Gilbertson

Thoughts on Tabbed Interfaces tutorial
The art of creating an accessible tabbed component, and whether you should.
Inclusive Components

Screen Capture in Google Chrome tutorial
How to access the screen capture capabilities of Google Chrome from within a web app.
Phil Nash

How to Build a Grid Inspector tutorial
A fun little project that aims to leave you with a better understanding of how the devtools Grid Inspector tool works.
Dave Geddes

Detect Supported Audio Formats with JavaScript tutorial
David Walsh

Creating Component Variants with Scoped CSS Variables tutorial
Jonathan Harrell

Get Your Dream Job In Tech - Learn to Code at Fullstack Academy 
Fullstack Academy is the nation's leading coding school - Our graduates get hired at Google, Facebook and Amazon.
Fullstack Academy  Sponsor

A Look Back at the History of CSS story
Jason Hoffman

Building a Modern Mobile Media Experience video
Francois Beaufort and John Pallett review best practices for mobile web media, including playback controls, pre-loading, autoplay and offline.
Google Chrome Developers

Axis-Praxis: OpenType Variable Fonts in the Browser tools
A web tool for playing with Variable Fonts.
Laurence Penney

SVG Regular Polygon Generator tools
Varun Vachhar

SQIP: A SVG-based 'Low Quality Image Preview' Technique code
Generate tiny SVG-based placeholders on the server side.
Tobias Baldauf

Monopoly Board Created with CSS Grid demo
John Coppola


by via Frontend Focus

Testing a Node.js API

Introduction

Tests are important; they provide a safeguard for your applications or APIs. As beginners, it is possible to be oblivious of the need to write tests that cover the important parts of what you are building. Yet you will meet with it as you make progress as a developer.

In a previous tutorial, you learned how to build an API with Node.js. If you have not gone through it, I suggest you do so before continuing with this. In this tutorial, you will be writing tests for an API built using Node.js and Express. At the end of this tutorial, you will know how testing works in Node.js, and you will be able to build functional and tested APIs.

Testing Tools

You will be making use of Mocha, Expect, and Supertest.

Mocha is a JavaScript test framework which makes asynchronous testing simple and fun. Mocha comes with tons of great features which can be found on the website. You will be making use of a handful of them.

Expect is an assertion library that makes it easy for you to make better assertions. You will see how that works. Supertest provides a high-level abstraction for testing HTTP. This is needful as you will be testing an API.

Enough talk, time to write some code.

Project Setup

I have a to-do list project already set up for you. The model, config file, and part of the app.js are already done for you. Go over to GitHub and clone the repository. Or you can simply do:

Your package.json should look like this.

Now run the command to install the dependencies.

POST Request Test

For your test, create a new folder called test; this folder should be in your server directory. Now create a new file where you will write your test. Name the file server.test.js.

In this file, start by requiring the modules you installed. You also need to require your server file and your model.

You need to have a few to-dos that will be used during tests. But these to-dos will be deleted from the test database each time you run your test suite. To handle that, create two tests like so.

The before block cleans your Todo database, then inserts the to-dos set above. This ensures that you have a stable amount of entries in your database so your tests do not run into issues.

With that done, you can write the test for the POST request. For your POST request, you will write two tests. The first will make a request for a valid to-do and be successful. The second will make a request with an invalid body, and this should not create a new to-do.

Here is what the test should look like.

Run the test using the command:

It should fail. Here is what is happening:

  1. Describes the test.
  2. Creates a new to-do and saves it as a value to text.
  3. You make a POST request to the /todos path of your API, sending the to-do you created as the body of the request. You expect the status code for the request to be 200 and the body of the to-do to equal the value of text.
  4. An error is returned if there is any, and this will cause the request to end. Thus the next block of code will not run. If no error is encountered, the flow continues.
  5. A request is made to the database to find the created to-do. You expect the length of the to-dos in the database to be 1, and the text of the to-do to be equal to the value of text.
  6. This is the test made with invalid body data.
  7. A POST request is made to the /todos path. This time, you are sending a request with no body. You expect to get a 400 request. No need to check the body as you are not sending any. If an error is encountered, it gets returned and the code stops running.
  8. If no error is encountered, a request is made to the database to check the length of the to-dos. We expect that the database will contain only 2, which are the to-dos created at the beginning.

To get this test passing, go to your server.js file and drop in the code needed for the POST request.

GET Request Test

This is simple—the test should return the length of to-dos available in the database. As you already know, the length of the todos should be 2. Why? You guessed right. At the beginning of the test suite, you created a beforeEach block that cleans your database and inserts new to-dos each time the test suite is run.

To test that the request to get all to-dos works, here is the code for that.

In the above, you are making a GET request to the /todos path. This time, you are not passing anything as the body of the request because it is a GET request. You expect to get a response with the status code of 200. Then you expect that the length of the to-dos will be 2.

When you run the test, you should get an error. Try getting the error to pass on your own.

I bet you got that to work. Here is the code to get the test to pass; compare it with your solution.

When a GET request is made to the /todos path, you want to find every to-do in the Todo collection and return them as to-dos. Adding this to server.js causes the test to pass.

Next, you'll write three tests for the GET request made to retrieve individual to-dos. The first should retrieve and return the to-do. The second and third should return 404 error in cases where the to-do is not found.

Open up your server.test.js and create a new describe block with the first test case.

This test makes a GET request to retrieve the first to-do available in your database. You expect to get a 200 status code, and then check that the text value of the to-do is the same as the one created.

The next test looks like this.

Here you are looking for a to-do using an ID that does not correspond to the ID of any to-do saved in your database. The test expects this request to return a 404 error.

The last test is like the first but a little different; here is how it looks.

Here, you create an invalid ObjectId and try to query the database to get a to-do matching the ObjectId created. The test expects the request to return a 404 error. 

When you run the test, they should all fail. To get them to pass, add the code below to your server.js file.

  1. Get the ID of the to-do requested from the params.
  2. Check to see if the ID is valid. If the ID is not valid, an error stating this is sent.
  3. If the ID is valid, try to find a to-do that matches that ID using the findById method. If no to-do is found with that ID, a 404 error is sent.
  4. If a to-do is found, the to-do is sent. Then you catch any error that occurs and sends it.

Run the test command once more, and it should pass.

DELETE Request Test

The test for your DELETE request will be a little like what you have for your GET request.

First, you want to test that a to-do is deleted.

Here is what is happening above:

  1. You set the id of the to-do to a variable called hexId. Next, a DELETE request is made to the path of the to-do, using the ID. You expect to get a 200 response, and the to-do obtained to match the value of hexId.
  2. If any error is encountered, it is returned.
  3. If no error, the test goes further to query your database using the ID saved as the value of hexId. Since a DELETE request has been previously sent, the test expects that the to-do matching that ID does not exist.

Next, you want to test that when a request is made to delete a to-do that does not exist, the response contains a 404 error. It is important to have this, as it is not possible to delete a to-do twice. Here is how the test for this should look.

This creates an ID for a to-do that does not exist in the database. Then a DELETE request is made to delete the to-do. The test is expected to return a 404 error as the to-do does not exist.

You want to test that a DELETE using an invalid ID returns a 404 error, like so.

To get the test to pass, open your server.js and drop this.

Run the command to test:

And your tests should be passing.

Conclusion

At this point, you now know how to set up a test suite when building an API using Node.js. You have used Mocha, Expect, and Supertest to test an API. One advantage of doing this is that you do not need to always fire up Postman when building your API. With your test, you can get to know what is broken.

Before we wrap up, note that JavaScript has become one of the de facto languages of working on the web. It’s not without its learning curves, and there are plenty of frameworks and libraries to keep you busy, as well. If you’re looking for additional resources to study or to use in your work, check out what we have available on Envato Market.

Using what you now know, you are good to explore the world of testing.


by Chinedu Izuchukwu via Envato Tuts+ Code

ReviewEmbed

Clean Landing Page with a subtle parallax effect as you begin to scroll for a Facebook Review integration service called ReviewEmbed. Also worth checking out the neat interactive style switcher demonstrating the four review embed options.

Full Review | Direct Link


by Rob Hope @robhope via One Page Love

Duft & Co Brickhouse

Excellent imagery in this dark-schemed One Pager for Duft & Co’s new ’Brickhouse’ restaurant.

Full Review | Direct Link


by Rob Hope @robhope via One Page Love

How to Legally Leverage User-Generated Content in Your Marketing

Do you want to use the images your fans and customers post on social media? Wondering how to secure permission to use your customers’ content? If you want user-generated content (UGC) for your marketing, you need to take steps to avoid potential legal hassles. In this article, you’ll discover how to use fan content legally [...]

This post How to Legally Leverage User-Generated Content in Your Marketing first appeared on .
- Your Guide to the Social Media Jungle


by Jim Belosic via

What Every Blogger Needs to Know About Logo Design - #infographic

There are so many resources to help you design a logo out there that you can easily begin to feel stressed and overwhelmed. You might need some guidance to understand which ideas are the ones you need to stick to, and that's exactly our goal with this article. The process of designing a logo...

[ This is a content summary only. Visit our website http://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Web Desk via Digital Information World